Skip to main content
On this page

Using KV in Node.js

Sunsetting on July 20, 2026

This page covers connecting to a Deno KV database hosted on Deno Deploy Classic (dash.deno.com). Deploy Classic will be shut down on July 20, 2026 — see the migration guide for details.

On the new Deno Deploy platform, KV databases are provisioned per app through the Databases feature and accessed from your app code via Deno.openKv() without a connection URL — see Deno KV on Deno Deploy. External KV Connect access to new‑Deploy KV databases is not currently exposed.

Connecting from Node.js to a Deno KV database hosted on Deno Deploy Classic is supported via our official client library on npm. You can find usage instructions for this option below. The same library can also connect to any other endpoint implementing the open KV Connect protocol, such as a self‑hosted denokv instance.

Installation and usage Jump to heading

Use your preferred npm client to install the client library for Node.js using one of the commands below.

>_
npm install @deno/kv
>_
pnpm add @deno/kv
>_
yarn add @deno/kv

Once you've added the package to your Node project, you can import the openKv function (supports both ESM import and CJS require-based usage):

import { openKv } from "@deno/kv";

// Connect to a KV instance
const kv = await openKv("<KV Connect URL>");

// Write some data
await kv.set(["users", "alice"], { name: "Alice" });

// Read it back
const result = await kv.get(["users", "alice"]);
console.log(result.value); // { name: "Alice" }

By default, the access token used for authentication comes from the DENO_KV_ACCESS_TOKEN environment variable. You can also pass it explicitly:

import { openKv } from "@deno/kv";

const kv = await openKv("<KV Connect URL>", { accessToken: myToken });

Once your Deno KV client is initialized, the same API available in Deno may be used in Node as well.

KV Connect URLs Jump to heading

Connecting to a KV database outside of Deno requires a KV Connect URL. A KV Connect URL for a database hosted on Deno Deploy Classic will be in this format: https://api.deno.com/databases/<database-id>/connect.

The database-id for your project can be found in the Deno Deploy Classic dashboard, under your project's "KV" tab.

Connection string locations in Deploy

More information Jump to heading

More information about how to use the Deno KV module for Node can be found on the project's README page.

Last updated on

Did you find what you needed?

Privacy policy
HTTPS · docs.deno.com
← Home