Skip to main content

Node.js Getting Started

Setup and generation

In the sdk/ directory, install dependencies and optionally generate SDKs from a running backend:

cd sdk
npm install
BASE_URL=http://localhost:8080 npm run generate
npm run build

If BASE_URL is not provided, the generator falls back to x-entities in doc/schemas/openapi.yaml. See sdk/typescript/examples/node/README.md for details.

Run the example

cd sdk
npm run generate
npm run build
BASE_URL=http://localhost:8080 npm run example:node

The example script hits /metadata/entities and /data endpoints and prints CRUD results to the console.

Code highlights (excerpt)

The snippet below from sdk/typescript/examples/node/index.js demonstrates generic CRUD operations:

const token = await fetchToken();
const ctx = { token, tenantId: process.env.TENANT_ID || '07c5b6ff', baseURL: process.env.BASE_URL || 'http://localhost:8080' };
const entity = process.env.ENTITY_NAME || 'customers';
const pkField = process.env.PK_FIELD || 'id';

const lst = await list(entity, ctx, { limit: 10, offset: 0 });
const filtered = await listFiltered(entity, ctx, { limit: 10, offset: 0 });

const created = await create(entity, { name: 'RecordUser', email: 'record.user@example.com', age: 25 }, ctx);
const createdOne = created[0] || null;

if (createdOne && createdOne[pkField] != null) {
const idv = createdOne[pkField];
const byId = await getById(entity, pkField, idv, ctx);
const updated = await updateById(entity, pkField, idv, { email: 'record.user+updated@example.com' }, ctx);
const deleted = await deleteById(entity, pkField, idv, ctx);
}

const updatedWhere = await updateWhere(entity, { op: 'and', conditions: [{ field: 'email', op: 'like', value: '%example.com' }] }, { age: 27 }, ctx);
const deletedWhere = await deleteWhere(entity, { op: 'and', conditions: [{ field: 'name', op: 'like', value: '%TempUser' }] }, ctx);

const upserted = await upsert(entity, ['email'], { name: 'RecordUpsert', email: 'record.upsert@example.com', age: 31 }, ctx);

For a real backend, ensure KC_*, TENANT_ID, and BASE_URL are configured correctly.