SDKs

Node.js

Load and read Veresk configs from a Node.js service.

Package: @veresk-tool/nodejs. Requires Node.js 18 or newer.

Install

npm install @veresk-tool/nodejs

Connect

The Integration page of your project generates this snippet with your CDN URL, version and consumer filled in.

import { Veresk, VereskEventName } from '@veresk-tool/nodejs';

const veresk = new Veresk({
  cdnUrls: ['<CDN URL>'],
  version: 'default',
  consumer: 'backend',
  encryptSecret: process.env.VERESK_SECRET,
});

veresk.on(VereskEventName.Error, (error) => console.error(error));

// Loads the manifest and files, then polls for updates.
await veresk.init();
OptionMeaning
cdnUrlsCDN URL of the project (from the Integration page).
versionVersion name, for example default.
consumerConsumer name.
encryptSecretThe project key. Needed only if some files are encrypted.

Read a config

Configs are served from memory by file name.

// A config by its file name.
const settings = veresk.getContent<Settings>('settings.json');

// One item of an array config.
const item = veresk.getAsListOrThrow<Item[]>('items.json', {
  find: { id: 'item-1' },
});

Notes

  • Keep VERESK_SECRET in the environment, not in code.
  • A version that was never published has no files for clients. Publish it first.