Skip to content
SDKs
Node.js

Node.js SDK

The Plunk Node.js SDK is a wrapper around the Plunk API that allows you to easily, and type-safely, interact with the Plunk API from your Node.js applications.

Source code for the SDK can be found on GitHub (opens in a new tab).

Installing

Install the SDK using a package manager of your choice:

npm i @plunk/node
 
yarn add @plunk/node

Getting Started

Interactions with the Plunk API are made through a client, create one using your secret key.

import Plunk from '@plunk/node';
 
const plunk = new Plunk("Your secret key");

Sending events

Use the events.track method to send events to Plunk.

Parameters

  • event: The name of the event to publish
  • email: The email address of the user to publish the event to
  • data [Optional]: An object containing the data to attach to the user
await plunk.events.track({
    event: "new-project",
    email: "hello@useplunk.com",
    data: {
        company: "Plunk"
    }
});

Sending emails

Use the emails.send method to send transactional emails.

Parameters
  • to: The email address of the recipient
  • subject: The subject of the email
  • body: The body of the email (HTML, plain text, or Markdown)
  • withUnsubscribe [Optional]: Whether to include an unsubscribe link hosted by Plunk in the email
await plunk.emails.send({
    to: "hello@useplunk.com",
    subject: "Welcome to Plunk",
    body: "<h1>Hello world!</h1>",
});
Last updated on April 21, 2023