Replit Database Client
The Replit Database client is a simple way to use Replit Database in your Node.js repls. The client expects to run within a Replit managed server context. Use this library in servers or other applications that execute on a Replit server, rather than in your user's browser.
Installation
Install the TypeScript Library with
npm install @replit/database
This library supports Bun, Deno, and Node.js (Node versions 18+ or any Node version polyfilled with the fetch API).
Quickstart
import Client from "@replit/database";
const client = new Client();
await client.set("key", "value");
let value = await client.get("key");
console.log(value);
Docs
Initiate a new database client:
import Client from "@replit/database";
new Client()
Retrieve a value for a key from the database:
const value = await client.get(key, )
console.log(value)
Sets a value for a key in the database:
await client.set(key, value)
Deletes a key from the database:
const result = await client.delete(key)
console.log(result.ok)
Lists all keys starting with the provided prefix:
const keys = await client.list("prefix-")
console.log(keys)
Clears the database:
await client.empty()
Gets all records in the database:
const records = await client.getAll()
Sets multiple key value pairs:
await client.setMultiple({keyOne: "valueOne", keyTwo: "valueTwo"})
Deletes multiple keys from the database:
await client.deleteMultiple(['keyOne', 'keyTwo'])
Tests
npm i
npm run test