PASTEDB
NODE.JS SDK
$ npm install pastedb-js
Node.js 18+ recommended — SDK uses built-in fetch API. A PasteDB API key for authenticated operations.
Uses native fetch(), no extra dependencies.
Sends both x-api-key and Authorization: Bearer <KEY>
const { Client } = require("pastedb-js");
const client = new Client("YOUR_API_KEY");
async function main() {
const user = await client.me();
console.log(user);
}
main().catch(console.error);Both parameters are optional. Default API URL is https://pastedb-rw62.onrender.com
const { Client } = require("pastedb-js");
const client = new Client(
"YOUR_API_KEY",
"https://pastedb-rw62.onrender.com"
);
// Both optional
const client2 = new Client();const user = await client.me();The data object is passed directly to API, allowing you to provide fields supported by PasteDB.
const paste = await client.createPaste({
title: "My Paste",
content: "Hello from PasteDB!",
images:[]
});const paste = await client.getPaste("paste-id");const updated = await client.updatePaste("paste-id", {
title: "Updated Title",
content: "Updated content",
images:["url1","url2"]
});const pastes = await client.explore();const result = await client.runCode(
"javascript",
'console.log("Hello, PasteDB!")'
);{
"language": "javascript",
"code": "console.log(\"Hello, PasteDB!\")"
}const images = await client.getImages("paste-id");const stats = await client.pasteStats("paste-id");const result = await client.checkCustomId("my-custom-id");const apiKey = await client.generateApiKey("My Application");{
"name": "My Application"
}const keys = await client.myApiKeys();await client.deleteApiKey("API_KEY");SDK also exposes methods corresponding to /api endpoints.
const user = await client.apiMe();const paste = await client.apiCreatePaste({
title: "API Paste",
content: "Created through the API"
});const paste = await client.apiGetPaste("paste-id");await client.apiDeletePaste("paste-id");const paste = await client.apiUpdatePaste("paste-id", {
title: "Updated Paste"
});const pastes = await client.apiUserPastes();Throws PasteDBError for API and timeout errors. Requests timeout after 30 seconds.
const { Client, PasteDBError } = require("pastedb-js");
const client = new Client("YOUR_API_KEY");
try {
const paste = await client.getPaste("invalid-id");
console.log(paste);
} catch (error) {
if (error instanceof PasteDBError) {
console.error("PasteDB error:", error.message);
} else {
console.error("Unexpected error:", error);
}
}
// Timeout throws:
// PasteDBError: Request timed out.const { Client, PasteDBError } = require("pastedb-js");
const client = new Client(process.env.PASTEDB_API_KEY);
async function main() {
try {
// Check the authenticated user
const user = await client.me();
console.log("User:", user);
// Create a paste
const paste = await client.createPaste({
title: "My First Paste",
content: "Hello from pastedb-js!",
images:[]
});
console.log("Created paste:", paste);
// Retrieve the paste
const fetched = await client.getPaste(paste.id);
console.log("Fetched paste:", fetched);
// Get statistics
const stats = await client.pasteStats(paste.id);
console.log("Stats:", stats);
} catch (error) {
if (error instanceof PasteDBError) {
console.error("PasteDB error:", error.message);
} else {
console.error(error);
}
}
}
main();const {
Client,
PasteDBError
} = require("pastedb-js");
// Client - Main SDK client
// PasteDBError - Custom error classpastedb-js/
├── lib/
│ └── client.js
├── index.js
├── LICENSE
├── package.json
└── README.mdMIT License — see LICENSE file.
Aditya Sorathiya
pastedb-js — Official PasteDB Node.js SDK v1.0.4
What is the PasteDB Node.js SDK?
The PasteDB Node.js SDK is an official JavaScript library for interacting with the PasteDB API from Node.js applications. It provides a simple interface for developers who want to create, retrieve, update and manage PasteDB pastes without manually constructing HTTP requests for every API operation.
The SDK can be used in Node.js projects, backend applications, developer tools, automation scripts and other JavaScript environments that need to work with PasteDB programmatically. Authentication is handled through a PasteDB API key, allowing applications to access the API using a straightforward client.
PasteDB API for Node.js
PasteDB provides a developer-focused API for working with code and text pastes. The Node.js SDK provides a convenient JavaScript interface over this API, making it easier to integrate PasteDB functionality into Node.js applications.
Create and manage pastes with JavaScript
Developers can use the PasteDB Node.js SDK to create new pastes, retrieve existing pastes and update paste content directly from JavaScript code. This can be useful for applications that need programmatic code sharing, text storage or PasteDB integration.
Retrieve PasteDB pastes programmatically
Instead of opening the PasteDB web application manually, a Node.js application can retrieve paste information through the SDK. This makes PasteDB suitable for scripts, internal developer tools and automated workflows that need access to paste data.
PasteDB API key authentication
The PasteDB Node.js SDK supports API key authentication. Developers can initialize the client with their PasteDB API key and then use the available SDK methods to interact with authenticated API endpoints.
Node.js SDK for developers
The SDK is designed to keep PasteDB API operations simple from JavaScript. Instead of repeatedly writing request handling code, developers can use methods provided by the PasteDB client to work with pastes, account information, API keys and other supported PasteDB functionality.
What can you do with the PasteDB Node.js SDK?
- Create PasteDB pastes from Node.js applications.
- Retrieve existing pastes using their IDs.
- Update paste content programmatically.
- View paste statistics where supported by the API.
- Explore publicly available PasteDB pastes.
- Run supported code through PasteDB.
- Check whether custom paste IDs are available.
- Generate and manage PasteDB API keys.
- Retrieve authenticated account information.
- Integrate PasteDB into JavaScript developer tools and scripts.
Why use a Node.js SDK instead of direct API requests?
Direct HTTP requests can be useful when building custom integrations, but an SDK can provide a more convenient programming interface for common operations. The PasteDB Node.js SDK groups supported API operations into a reusable client so developers can work with PasteDB using familiar JavaScript methods.
PasteDB for JavaScript developers
Whether you are building a backend service, automation script, developer utility or another Node.js application, the PasteDB Node.js SDK provides a programmatic way to connect your project with PasteDB. The documentation above contains installation instructions, authentication details, available methods and complete usage examples.