Node SDK
Install & Auth
The memorysync-sdk package installs from the public npm registry under that exact name. This page covers the install command, every constructor option (with defaults), and a one-liner you can run in production to confirm a key is reaching the right environment.
Install
BASH
# npmnpm install memorysync-sdk# pnpmpnpm add memorysync-sdk# yarnyarn add memorysync-sdk
Watch the package name
The npm package is
memorysync-sdk, not memorysync. The unsuffixed name on npm is not us. The Python package is memorysync; only Node has the suffix.Verify the install
BASH
node -e "const {MemorySyncClient}=require('memorysync-sdk'); const v=require('memorysync-sdk/package.json').version; console.log('OK', v);"
Every constructor option
| Option | Type | Default | When to set it |
|---|---|---|---|
| apiKey | string | — (required) | Always. |
| baseUrl | string | — (required) | Per-environment URL. |
| projectId | string | undefined | Lock this client to one project. |
| endUserId | string | undefined | Required when authenticating with an API key. Identifies which of your end users the request belongs to; sent as the X-End-User-ID header. The server returns 400 MISSING_END_USER_ID without it. Can be overridden per call on add(). |
| timeoutMs | number | 30000 | Per-request ceiling in milliseconds. |
| fetch | typeof fetch | globalThis.fetch | Pass a custom fetch (e.g. an instrumented one). |
Building the client
TYPESCRIPT
import { MemorySyncClient } from "memorysync-sdk";const client = new MemorySyncClient({apiKey: process.env.MEMORYSYNC_API_KEY!,baseUrl: "https://api.memorysync.io",endUserId: "user_123", // required for API-key authprojectId: process.env.MEMORYSYNC_PROJECT_ID,timeoutMs: 15_000,});
Splitting environments
BASH
# .env.localMEMORYSYNC_API_KEY=ms_test_...MEMORYSYNC_BASE_URL=https://staging.api.memorysync.io# .env.productionMEMORYSYNC_API_KEY=ms_live_...MEMORYSYNC_BASE_URL=https://api.memorysync.io
A safe “hello world”
Run this once after wiring credentials. It does not write anything; it only confirms the client can reach the API and the key is valid.
TYPESCRIPT
// Reuses the client from the snippet above (with endUserId set).try {const exp = await client.exportAll();console.log("OK userId =", exp.userId);} catch (e: any) {if (e?.name === "AuthError") console.error("Invalid key");else throw e;}
Plugging in a custom fetch
Inject your own fetch if you want to attach tracing, add a corporate proxy, or run inside an environment with a non-standard global.
TYPESCRIPT
const traced: typeof fetch = (url, init) => {console.log("[memorysync]", init?.method ?? "GET", url);return fetch(url, init);};const client = new MemorySyncClient({apiKey: ..., baseUrl: ..., fetch: traced,});
Rotating a leaked key
- Create a new key in the dashboard.
- Roll it out to your secret manager and restart your services.
- Confirm the new key is in use, then delete the old key. The dashboard revokes it immediately.