Pastebin API

Published 7 months ago - 2 min read

On February 23rd I created my second npm package "pastebin-api", it's a package to interact with the Pastebin api.

Getting started



npm install pastebin-api


yarn add pastebin-api

Creating the client

We will first import the client using:

// import/export
import PasteClient from "pastebin-api";

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

After importing, we'll create the client

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