npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pastedb-js

v1.0.4

Published

Official PasteDB Node.js SDK

Readme

PasteDB JavaScript SDK

Official Node.js SDK for interacting with the PasteDB API.

Create, retrieve, update, delete, and explore pastes, execute code, manage API keys, retrieve paste statistics, and more — directly from your Node.js application.

Installation

npm install pastedb-js

Requirements

  • Node.js 18+ recommended
  • A PasteDB API key for authenticated operations

The SDK uses the built-in fetch API available in modern versions of Node.js.

Quick Start

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);

Configuration

Client

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

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

Both parameters are optional:

const client = new Client();

The default API URL is:

https://pastedb-rw62.onrender.com

If an API key is provided, the SDK automatically sends it using both:

  • x-api-key
  • Authorization: Bearer <API_KEY>

API Reference

Get Current User

const user = await client.me();

Equivalent endpoint:

GET /api/me

Create a Paste

const paste = await client.createPaste({
    title: "My Paste",
    content: "Hello from PasteDB!",
    images:[]
});

Equivalent endpoint:

POST /create

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


Get a Paste

const paste = await client.getPaste("paste-id");

Equivalent endpoint:

GET /p/:pasteId

Update a Paste

const updated = await client.updatePaste("paste-id", {
    title: "Updated Title",
    content: "Updated content",
    images:["url1","url2"]
});

Equivalent endpoint:

PUT /api/paste/:pasteId

Explore Public Pastes

const pastes = await client.explore();

Equivalent endpoint:

GET /explore

Run Code

const result = await client.runCode(
    "javascript",
    'console.log("Hello, PasteDB!")'
);

Equivalent endpoint:

POST /run

Request body:

{
    "language": "javascript",
    "code": "console.log(\"Hello, PasteDB!\")"
}

Get Paste Images

const images = await client.getImages("paste-id");

Equivalent endpoint:

GET /images/:pasteId

Get Paste Statistics

const stats = await client.pasteStats("paste-id");

Equivalent endpoint:

GET /stats/:pasteId

Check a Custom Paste ID

const result = await client.checkCustomId("my-custom-id");

Equivalent endpoint:

GET /check-id?id=my-custom-id

API Key Management

Generate an API Key

const apiKey = await client.generateApiKey("My Application");

Equivalent endpoint:

POST /generate-api-key

Request body:

{
    "name": "My Application"
}

List API Keys

const keys = await client.myApiKeys();

Equivalent endpoint:

GET /my-api-keys

Delete an API Key

await client.deleteApiKey("API_KEY");

Equivalent endpoint:

DELETE /delete-api-key/:apiKey

Keep API keys private and never commit them to source control.

Direct API Methods

The SDK also exposes methods corresponding to the /api endpoints.

API User

const user = await client.apiMe();
GET /api/me

Create a Paste

const paste = await client.apiCreatePaste({
    title: "API Paste",
    content: "Created through the API"
});
POST /api/create

Get a Paste

const paste = await client.apiGetPaste("paste-id");
GET /api/paste/:pasteId

Delete a Paste

await client.apiDeletePaste("paste-id");
DELETE /api/paste/:pasteId

Update a Paste

const paste = await client.apiUpdatePaste("paste-id", {
    title: "Updated Paste"
});
PUT /api/paste/:pasteId

Get Your Pastes

const pastes = await client.apiUserPastes();
GET /api/pastes

Error Handling

The SDK provides a custom PasteDBError class for API and request errors.

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);
    }
}

Request Timeout

Requests automatically time out after 30 seconds.

A timeout throws:

PasteDBError: Request timed out.

HTTP errors are also converted into PasteDBError instances and include the HTTP status code and API response.

Complete Example

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();

Exported Classes

The package exports:

const {
    Client,
    PasteDBError
} = require("pastedb-js");

Client

Main SDK client used to communicate with PasteDB.

PasteDBError

Custom error class used for PasteDB request failures and timeouts.

Project Structure

pastedb-js/
├── lib/
│   └── client.js
├── index.js
├── LICENSE
├── package.json
└── README.md

License

This project is licensed under the MIT License.

Author

Aditya Sorathiya

Package

pastedb-js — Official PasteDB Node.js SDK.