---
title: JavaScript and TypeScript
summary: 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.
order: 10
languages: [javascript, typescript]
terms: [sdk, api-token, qid]
see-also: [reference/sdk/typescript, reference/javascript, reference/sdk, how-to/install/java]
---

# JavaScript and TypeScript

There are two JavaScript [[term:sdk|SDKs]] ([[page:reference/sdk]] 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 ([[page:reference/sdk/typescript]]).
- the **classic JavaScript SDK**, `@bimworks/jssdk`, which the 3D and 2D viewers build on: a page with a viewer uses it ([[page:reference/javascript]]).

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 ([[page:how-to/install/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:

```shell
npm login --registry=https://npm.bim.works --scope=@sascom
npm login --registry=https://npm.bim.works --scope=@bimworks
```

Or edit `~/.npmrc` by hand and log in once:

```text
@sascom:registry=https://npm.bim.works
@bimworks:registry=https://npm.bim.works
```

Then 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 {#typescript-sdk}

```json {#dependencies-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`); [[page:reference/sdk/typescript#package]] has the `tsconfig.json` settings. To check the installation, run the program below; it logs in with your [[term:api-token|API token]] and prints the UUID of your root node:

```sdk-example {#check-sdk}
operation: GetRootNodeUuid
languages: typescript
```

## The classic SDK and the viewers {#classic}

```json {#dependencies}
"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 ([[page:how-to/viewer3d/choose-the-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:

```javascript {#first-lines}
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);
```

```note
Uploads from Node.js go over HTTP instead of the WebSocket transport: `{upload: {useHttp: true}}` is the default there.
```
