OpenZiti is a free and open source project focused on bringing zero trust to any application.
The project provides all the pieces required to implement or integrate zero trust into your solutions.
Please star us.
@openziti/ziti-sdk-nodejs
This repo hosts the OpenZiti SDK for NodeJS, and is designed to help you deliver secure applications over a OpenZiti Network
Part of the OpenZiti ecosystem
Are you interested in knowing how to easily embed programmable, high performance, zero trust networking into your NodeJS app, on any internet connection, without VPNs?
Learn more about our OpenZiti project.
For more context on this SDK, you may be interested in this article concerning how to secure NodeJS applications
The @openziti/ziti-sdk-nodejs module works with the following Node.js versions:
- v22.x
- v24.x
- v26.x
The @openziti/ziti-sdk-nodejs module works with the following architectures:
- amd64
- arm64
The @openziti/ziti-sdk-nodejs module works with the following Operating Systems:
- macos
- linux
- windows
NPM
npm i @openziti/ziti-sdk-nodejsor Yarn
yarn add @openziti/ziti-sdk-nodejsSpecial note on previous package:
On June 7, 2020 @openziti/ziti-sdk-nodejs@0.6.0 was released. Older, unscoped versions that are not part of the @openziti org are deprecated and only @openziti/ziti-sdk-nodejs will see updates going forward. To upgrade to the new package do:
npm uninstall ziti-sdk-nodejs --save
npm install @openziti/ziti-sdk-nodejs --saveNote: the module must be installed before use.
ESM example (client-side)
import ziti from '@openziti/ziti-sdk-nodejs';
// Somehow provide path to identity file, e.g. via env var
const zitiIdentityFile = process.env.ZITI_IDENTITY_FILE;
// Authenticate ourselves onto the Ziti network
await ziti.init( zitiIdentityFile ).catch(( err ) => { /* probably exit */ });
const on_resp_data = ( obj ) => {
console.log(`response is: ${obj.body.toString('utf8')}`);
};
// Perform an HTTP GET request to a dark OpenZiti web service
ziti.httpRequest(
'myDarkWebService', // OpenZiti Service name or HTTP origin part of the URL
undefined, // schemeHostPort parm is mutually-exclusive with serviceName parm
'GET',
'/', // path part of the URL including query params
['Accept: application/json' ], // headers
undefined, // optional on_req cb
undefined, // optional on_req_data cb
on_resp_data // optional on_resp_data cb
);ESM example (server-side ExpressJS)
import ziti from '@openziti/ziti-sdk-nodejs';
import express from 'express';
let app = ziti.express( express, zitiServiceName );
app.listen(ignored, function() { ... }
/**
That's right.
With only a single-line code change (the ziti.express call), your web server is now capable
of being invisible to malicious attackers on the internet, and only accessible to your
trusted remote users.
Nothing else in your existing ExpressJS web server code needs to change!
Existing routing, middleware, etc., all operates the same as it always did...
but now you enjoy the comfort of knowing that if a connection comes in, it is from
a trusted identity on the client side.
No malicious actors can see your dark web server, and thus, no malicious actors can attack it.
*/CJS example (client-side)
var ziti = require('@openziti/ziti-sdk-nodejs');
const ziti_init = async (identity) => {
return new Promise((resolve) => {
ziti.ziti_init(identity, () => {
resolve();
});
});
};
const ziti_service_available = (service) => {
return new Promise((resolve) => {
ziti.ziti_service_available(service, (status) => {
resolve(status);
});
});
};
function ziti_dial(service) {
return new Promise((resolve, reject) => {
ziti.ziti_dial(
service,
(conn) => {
resolve(conn);
},
(data) => {
// Do something with data...
},
);
});
}
const ziti_write = (conn, data) => {
return new Promise((resolve) => {
ziti.ziti_write(conn, data, () => {
resolve();
});
});
};
(async () => {
await ziti_init(LOCATION_OF_IDENTITY_FILE);
let status = await ziti_service_available(YOUR_SERVICE_NAME);
if (status === 0) {
const conn = await ziti_dial(YOUR_SERVICE_NAME);
let data = SOME_KIND_OF_DATA;
let buffer = Buffer.from(data);
await ziti_write(conn, buffer);
...etc
}
})();For doc concerning API's contained in this SDK, you may be interested in this SDK API Reference
Please use these community resources for getting help. We use GitHub issues for tracking bugs and feature requests and have limited bandwidth to address them.
git clone https://github.com/microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh
export VCPKG_ROOT=`pwd`/vcpkg
brew install cmake
brew install ninja
brew install pkg-config
brew install autoconf autoconf-archive automake libtool
git clone https://github.com/openziti/ziti-sdk-nodejs.git
cd ziti-sdk-nodejs
npm run buildThe same steps as on MacOS, with the build tools from the package manager. vcpkg builds libsodium with autotools, so those are needed too (Debian/Ubuntu):
sudo apt install -y build-essential cmake ninja-build pkg-config autoconf autoconf-archive automake libtoolnpm test runs the unit tests (tests/*.test.*js). They load the built addon and need no Ziti network, so
build first (npm run build).
npm run test:integ runs tests/integ/*.test.mjs against a real Ziti network: enrolling an identity, dialing and
binding a service (echo), and httpRequest against an Express app served over Ziti with ziti.express.
What you need:
- the built addon (
npm run build) and the dev dependencies (npm ci, which brings Express for the test server); - the
zitiCLI on thePATH(orZITI_CLI=/path/to/ziti).
CI runs them on every supported Node.js on Linux x64, macOS (arm64 and x64) and Windows x64, against the latest
release of each ziti LTS line (lts-versions.json in openziti/ziti). ZITI_CLI points a local run at any release.
tests/integ/run.mjs starts a throwaway ziti edge quickstart, runs the tests against it and stops it, whatever
happens. The quickstart has its own ziti edge login, so your own CLI login is not touched.
It listens on controller port 1280, so there can be only one on a machine: stop the quickstart of the C or Python
suites first (the runner says so if the port is taken). The JUnit report goes to testdata/integ-results.xml.
The quickstart's directory is kept, after every run, in testdata/quickstart (git-ignored), so that a failing test
can be looked into afterwards: qs.log, the quickstart's data, the identities and JWTs the tests created and the
logs of their server processes are in it. The next run replaces it. To bring the network back up and look at it with
the ziti CLI, which the quickstart logged in inside that directory:
ziti edge quickstart --home testdata/quickstart
ZITI_CONFIG_DIR=testdata/quickstart/cli ziti edge list identities # in another terminalThe directory holds the private keys of the throwaway network's identities.
To iterate against a quickstart you already have running (and are logged in to with the ziti CLI), skip the
startup:
ZITI_INTEG_EXISTING=1 npm run test:integA single test file, by hand, against that running quickstart:
ZITI_INTEG=1 node --test tests/integ/dial-echo.test.mjs| Variable | Meaning |
|---|---|
ZITI_CLI |
the ziti executable (default ziti) |
ZITI_INTEG_EXISTING=1 |
use the running quickstart, start and stop nothing |
ZITI_INTEG_CTRL_PORT |
controller port to probe (default 1280); the quickstart itself is not told |
ZITI_INTEG_READY_TIMEOUT_MS |
wait for the quickstart to come up (default 90000) |
ZITI_INTEG_KILL_TIMEOUT_MS |
SIGTERM-to-SIGKILL delay when stopping it (default 10000) |
ZITI_INTEG_TEST_FILES |
space-separated test files to run instead of all of them |
ZITI_LOG |
SDK log level in the test processes (default 3) |
Copyright© NetFoundry, Inc.

