Pastebin API

March 27, 2021


On February 23rd I created my second npm package "pastebin-api". This package can be used to interacte with the Pastebin API to create pastes, list pastes and delete pastes.



npm install pastebin-api


yarn add pastebin-api

Creating the client

First, we must import the PasteClient class from pastebin-api.

// es6
import PasteClient from "pastebin-api";
// commonjs
const PasteClient = require("pastebin-api").default;

Instantiating the client

Replace process.env["API_KEY_HERE"] with your own api key from Pastebin. I recommend you add this key into a .env file.

const client = new PasteClient(process.env["API_KEY_HERE"]);

Creating a new paste

Now we'll create a new paste using the .createPaste method

const pasteUrl = await client.createPaste({
  code: "const hello = 'hello world!'", // The code we want to send in the Paste
  expireDate: "N", // When should the paste expire
  format: "javascript", // The format, "javascript", "java", "lua", etc
  name: "hello.js", // The name of the paste
  publicity: 0, // 0 for a public paste
console.log(pasteUrl); // if an error occurred, it'll be thrown to the console.

Woohoo 🎉

There you have it! We've successfully created a new paste! Read more on the docs