JavaScript and TypeScript
Install the @bimworks packages from the private npm registry — the TypeScript SDK generated from the OpenAPI, or the classic JavaScript SDK with the viewers — or use the single-file builds with an import map.
There are two JavaScript SDKs (SDKs compares them):
- the TypeScript SDK,
@bimworks/sdk, generated from the OpenAPI document, for TypeScript and JavaScript in Node.js and browsers. Use it for an integration without a viewer (TypeScript SDK). - the classic JavaScript SDK,
@bimworks/jssdk, which the 3D and 2D viewers build on: a page with a viewer uses it (Classic JavaScript SDK).
The packages come from the npm registry. They are ES modules that import each other by package name (@bimworks/viewercommon, @sascom/commonjs/logger.js), so they are meant for a project with a bundler (Vite, webpack, Angular CLI) or for Node.js. A page without a build step uses the single-file modules, served from its own site, with an import map that resolves those names (Downloads).
npm registry#
The packages live in two scopes, @bimworks and @sascom, on https://npm.bim.works. Point both scopes at the registry and log in once per scope:
npm login --registry=https://npm.bim.works --scope=@sascom
npm login --registry=https://npm.bim.works --scope=@bimworksOr edit ~/.npmrc by hand and log in once:
@sascom:registry=https://npm.bim.works
@bimworks:registry=https://npm.bim.worksThen add the packages you need. Use the same version for all of them, and the version that matches your BIM.works server (the version pill at the top of this page is the server's).
The TypeScript SDK#
"dependencies": {
"@bimworks/sdk": "3.0.0-beta.192"
}It has no dependencies of its own and talks to the server with fetch, so it runs in Node.js 20 or later and in browsers. Its examples are ES modules with top-level await ("type": "module" in package.json); reference/sdk/typescript#package has the tsconfig.json settings. To check the installation, run the program below; it logs in with your API token and prints the UUID of your root node:
import { AuthApi, Configuration, FsApi } from "@bimworks/sdk";
// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
.loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });
// 2. The request
// (GetRootNodeUuid takes no request)
// 3. The call
const result = await new FsApi(client).getRootNodeUuid();
// 4. The result
console.log(result);The classic SDK and the viewers#
"dependencies": {
"@bimworks/jssdk": "3.0.0-beta.192",
"@bimworks/viewercommon": "3.0.0-beta.192",
"@bimworks/viewer3d": "3.0.0-beta.192",
"@bimworks/viewer2d": "3.0.0-beta.192"
}| Package | What it is |
|---|---|
@bimworks/jssdk |
The API client: nodes and versions, queries, checks, uploads, tokens, geo referencing. |
@bimworks/viewercommon |
The ModelManager and ObjectStateManager both viewers share, plus Qid, QidSet and QidMap. |
@bimworks/viewer3d |
The 3D viewer. Needs viewercommon and jssdk. |
@bimworks/viewer3d-next |
The 3D viewer on WebGPU, with the same API as viewer3d, for browsers whose WebGPU can run it. Needs viewercommon and jssdk. |
@bimworks/viewer3d-auto |
Picks one of the two 3D viewers per browser and downloads only that one (Choose the 3D viewer). Brings both. |
@bimworks/viewer2d |
The 2D viewer. Needs viewercommon and jssdk. |
The registry also has a @bimworks/viewers package. It currently exports only its version, not the packages above, so install those separately.
The first lines of any application:
import {BimWorksClientFactory} from "@bimworks/jssdk";
import {ModelManager, ObjectStateManager} from "@bimworks/viewercommon";
import {Viewer3d} from "@bimworks/viewer3d";
const factory = new BimWorksClientFactory("https://bim.works");
const client = await factory.createClientWithApiToken(apiToken);Uploads from Node.js go over HTTP instead of the WebSocket transport: {upload: {useHttp: true}} is the default there.