PASTEDB / NODE.JS SDK / v1.0.4 / BLUEPRINT
NODE>=18● ONLINE
[ OFFICIAL / PASTEDB-JS / README SOURCE OF TRUTH ]

PASTEDB
NODE.JS SDK

Official Node.js SDK for interacting with PasteDB API. Create, retrieve, update, delete, explore pastes, execute code, manage API keys, retrieve stats and more — directly from Node.js.
BASH — INSTALL / pastedb-jsv1.0.4
$ npm install pastedb-js
01
REQUIREMENTS

Node.js 18+ recommended — SDK uses built-in fetch API. A PasteDB API key for authenticated operations.

NODE.JS >=18

Uses native fetch(), no extra dependencies.

API KEY OPTIONAL

Sends both x-api-key and Authorization: Bearer <KEY>

02
QUICK START
JSQUICKSTART.JS
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);
03
CONFIGURATION / CLIENT

Both parameters are optional. Default API URL is https://pastedb-rw62.onrender.com

JSCLIENT CONFIG
const { Client } = require("pastedb-js");

const client = new Client(
    "YOUR_API_KEY",
    "https://pastedb-rw62.onrender.com"
);

// Both optional
const client2 = new Client();
AUTH HEADERS: If API key provided, SDK automatically sends it using both x-api-key and Authorization: Bearer <API_KEY>
04
GET CURRENT USER — me()
GET /api/me
JSme()
const user = await client.me();
05
CREATE A PASTE — createPaste()
POST /create

The data object is passed directly to API, allowing you to provide fields supported by PasteDB.

JScreatePaste()
const paste = await client.createPaste({
    title: "My Paste",
    content: "Hello from PasteDB!",
    images:[]
});
06
GET A PASTE — getPaste(id)
GET /p/:pasteId
JS
const paste = await client.getPaste("paste-id");
07
UPDATE A PASTE — updatePaste()
PUT /api/paste/:pasteId
JS
const updated = await client.updatePaste("paste-id", {
    title: "Updated Title",
    content: "Updated content",
    images:["url1","url2"]
});
08
EXPLORE PUBLIC PASTES — explore()
GET /explore
JS
const pastes = await client.explore();
09
RUN CODE — runCode(lang, code)
POST /run
JS
const result = await client.runCode(
    "javascript",
    'console.log("Hello, PasteDB!")'
);
JSONREQUEST BODY
{
    "language": "javascript",
    "code": "console.log(\"Hello, PasteDB!\")"
}
10
GET PASTE IMAGES — getImages()
GET /images/:pasteId
JS
const images = await client.getImages("paste-id");
11
GET PASTE STATISTICS — pasteStats()
GET /stats/:pasteId
JS
const stats = await client.pasteStats("paste-id");
12
CHECK CUSTOM ID — checkCustomId()
GET /check-id?id=my-custom-id
JS
const result = await client.checkCustomId("my-custom-id");
13
AUTH / API KEY MANAGEMENT
POSTgenerateApiKey(name)
POST /generate-api-key
JS
const apiKey = await client.generateApiKey("My Application");
JSONBODY
{
  "name": "My Application"
}
GETmyApiKeys()
GET /my-api-keys
JS
const keys = await client.myApiKeys();
DELdeleteApiKey(key)
DELETE /delete-api-key/:apiKey
JS
await client.deleteApiKey("API_KEY");
Keep API keys private and never commit them to source control.
14
DIRECT API METHODS — /api/*

SDK also exposes methods corresponding to /api endpoints.

GETapiMe()
GET /api/me
JS
const user = await client.apiMe();
POSTapiCreatePaste()
POST /api/create
JS
const paste = await client.apiCreatePaste({
    title: "API Paste",
    content: "Created through the API"
});
GETapiGetPaste()
GET /api/paste/:pasteId
JS
const paste = await client.apiGetPaste("paste-id");
DELapiDeletePaste()
DELETE /api/paste/:pasteId
JS
await client.apiDeletePaste("paste-id");
PUTapiUpdatePaste()
PUT /api/paste/:pasteId
JS
const paste = await client.apiUpdatePaste("paste-id", {
    title: "Updated Paste"
});
GETapiUserPastes()
GET /api/pastes
JS
const pastes = await client.apiUserPastes();
!
ERROR HANDLING — PasteDBError

Throws PasteDBError for API and timeout errors. Requests timeout after 30 seconds.

JSERROR / TIMEOUT
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.
★
COMPLETE EXAMPLE — FULL FLOW
JSCOMPLETE.JS — PRODUCTION READY
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();
17
EXPORTED CLASSES / STRUCTURE / LICENSE
EXPORTED CLASSES
JS
const {
    Client,
    PasteDBError
} = require("pastedb-js");

// Client - Main SDK client
// PasteDBError - Custom error class
PROJECT STRUCTURE
TREE
pastedb-js/
├── lib/
│ └── client.js
├── index.js
├── LICENSE
├── package.json
└── README.md
LICENSE

MIT License — see LICENSE file.

AUTHOR / PACKAGE

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.

COPIED_