> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js

> Use Bijection HTTP and subscription clients in Node.js applications

Bijection supports point-in-time queries (see
[HTTP client](/api/classes/browser.BijectionHttpClient)) and query subscriptions
(see [BijectionClient](/api/classes/browser.BijectionClient)) in Node.js.

If your JavaScript code uses import/export syntax, calling Bijection functions
works just like in a browser.

```js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { BijectionHttpClient, BijectionClient } from "bijection/browser";
import { api } from "./bijection/_generated/api.js";

// HTTP client
const httpClient = new BijectionHttpClient(BIJECTION_URL_GOES_HERE);
httpClient.query(api.messages.list).then(console.log);

// Subscription client
const client = new BijectionClient(BIJECTION_URL_GOES_HERE);
client.onUpdate(api.messages.list, {}, (messages) => console.log(messages));
```

## TypeScript

Just like bundling for the browser, bundling TypeScript code for Node.js with
webpack, esbuild, rollup, vite, and others usually allow you import from code
that uses import/export syntax with no extra setup.

If you use TypeScript to *compile* your code (this is rare for web projects but
more common with Node.js), add `"allowJs": true` to `tsconfig.json` compiler
options so that TypeScript will compile the `api.js` file as well.

## TypeScript without a compile step

If you want to run your TypeScript script directly without a compile step,
installing [ts-node-esm](https://www.npmjs.com/package/ts-node) and running your
script with ts-node-esm should work if you use `"type": "module"` in your
`package.json`.

## JavaScript with CommonJS (`require()` syntax)

If you don't use `"type": "module"` in the `package.json` of your project you'll
need to use `require()` syntax and Node.js will not be able to import the
`bijection/_generated/api.js` file directly.

In the same directory as your `package.json`, create or edit
[`bijection.json`](/config/bijection-json):

```json bijection.json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "generateCommonJSApi": true
}
```

When the `bijection dev` command generates files in `bijection/_generated/` a new
`api_cjs.cjs` file will be created which can be imported from CommonJS code.

```js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const { BijectionHttpClient, BijectionClient } = require("bijection/browser");
const { api } = require("./bijection/_generated/api_cjs.cjs");
const httpClient = new BijectionHttpClient(BIJECTION_URL_GOES_HERE);
```

## TypeScript with CommonJS without a compile step

Follow the steps above for CommonJS and use
[`ts-node`](https://www.npmjs.com/package/ts-node) to run you code. Be sure your
`tsconfig.json` is configured for CommonJS output.

## Using Bijection with Node.js without codegen

You can always use the `anyApi` object or strings if you don't have the Bijection
functions and api file handy. An api reference like `api.folder.file.exportName`
becomes `anyApi.folder.file.exportName` or `"folder/file:exportName"`.
