Toggle menu

Pastebin API

Learn more about my npm package.

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

Installation

npm

# Replace npm with your package manager of choice
npm install pastebin-api
bash

Creating the client

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

src/index.ts
// es6
import { PasteClient } from "pastebin-api";
 
// commonjs
const { PasteClient } = require("pastebin-api");
ts

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.

src/index.ts
const client = new PasteClient(process.env["API_KEY_HERE"]);
ts

Creating a new paste

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

src/index.ts
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.
ts

Woohoo 🎉

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