How to Use Notify with Node.js

Send your first email with Notify in a Node.js app in minutes.

Prerequisites

Before you start, make sure you have:

  • Your API key – We generated one for you when you signed up. This authenticates your Node.js app and lets you send emails.
  • A verified domain (optional) – Not required for testing. Trial accounts can send up to 100 emails total (10/hr limit). To scale beyond that, verify your domain for better deliverability.

1. Install the SDK

Get the Notify Node.js SDK:

# npm
npm install notifycx

# yarn
yarn add notifycx

# pnpm
pnpm add notifycx

2. Send an Email

Set up a simple Node.js script to send an email:

import Notify from 'notifycx';
import dotenv from 'dotenv';

dotenv.config();

const notify = new Notify(process.env.NOTIFY_API_KEY);

async function sendEmail() {
  const response = await notify.sendEmail({
    to: 'john@example.com',
    subject: 'Hello world',
    name: 'John Doe',
    message: 'Your email content here'
  });
  console.log(response);
}

sendEmail();

Place this in a file like send-email.js and run it with:

node send-email.js

The message field can be plain text or HTML, depending on your needs. If you need styling, links, or images, use HTML.


3. Sending Template-Based Emails

At Notify, we recommend you don't hand-code HTML for your emails — use Notify templates instead. Notify offers an intuitive template builder with pre-made and fully customizable templates. These support dynamic variables for personalization.

Once you’ve created a template, grab its ID from here and use it like this:

async function sendTemplatedEmail() {
  try {
    const response = await notify.sendEmailFromTemplate({
      to: 'john@example.com',
      from: 'noreply@notify.cx',
      templateId: '<your_template_id>',
      variables: {
        name: 'John Doe',
        company: 'Example Inc.'
      }
    });

    console.log(response);
  } catch (error) {
    console.error('Failed to send template email:', error);
  }
}

sendTemplatedEmail();

Both sendEmail and sendEmailFromTemplate throw errors if the request fails. Always wrap them in try/catch.


If you need to use CommonJS, you can do so like this:

// Send email
const Notify = require('notifycx').default;

const notify = new Notify('<your_api_key>');

async function sendEmail() {
  const response = await notify.sendEmail({
    to: 'john@example.com',
    subject: 'Hello world',
    name: 'John Doe',
    message: 'Your email content here'
  });
  console.log(response);
}

sendEmail();

Where To Next?

Now you’re ready to send emails in your Node.js app with Notify! 🚀