@plunk/node
v3.0.3
Published
Official Node.js library for useplunk.com
Downloads
14,800
Readme
Plunk Node.js
This project contains the helper library for interacting with the Plunk API using Node.js.
Table of contents
Installation
Installing the latest version can be done through your package manager.
npm i @plunk/node
yarn add @plunk/node
Getting started
Any interaction you want to make with the Plunk API needs to be done through the Plunk client. You can use a default import to get started.
import Plunk from '@plunk/node';
// Using the default API URL
const plunk = new Plunk("Your secret key");
// Or specifying a custom API URL
const plunkCustom = new Plunk("Your secret key", { baseUrl: "https://selfhosted.example.com/api/v1/" });
API
Events
track()
Used to publish an event
Parameters
event
: The name of the event to publishemail
: The email address of the user to publish the event tosubscribed
[Optional]: Whether to the contact is subscribed to marketing emails, defaults totrue
data
[Optional]: An object containing the data to attach to the user
const success = await plunk.events.track({
event: "new-project",
email: "[email protected]",
data: {
company: "Plunk"
}
});
Emails
send()
Used to send a transactional email
Parameters
to
: The email address of the recipientsubject
: The subject of the emailbody
: The body of the emailtype
[Optional]: The type of email to send (html
ormarkdown
)from
[Optional]: The email address of the sendername
[Optional]: The name of the sendersubscribed
[Optional]: Whether to the contact is subscribed to marketing emails, defaults tofalse
const success = await plunk.emails.send({
to: "[email protected]",
subject: "Welcome to Plunk",
body: "Hello world!",
});