Pastebin API

Casper Iversen March 27, 2021 - 2 min read

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

No need to install types since pastebin-api was created using Typescript and includes built in types!

npm install pastebin-api
yarn add pastebin-api

We will first import the client using:

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

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

Note: Replace process.env["API_KEY_HERE"] with your own api key from Pastebin. You can also add it in a .env file.

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

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.

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