How to Use Notify with Node.js
Send email from Node.js with fetch — no packages required.
Send email from a Node.js app with a single fetch call. Node.js 18+ includes global fetch — no extra packages required.
Prerequisites
- API key — generated when you sign up
- Verified domain (optional) — required for production sends from a custom
fromaddress
Send an email
async function sendEmail() {
const response = await fetch('https://notify.cx/api/email/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': process.env.NOTIFY_API_KEY!
},
body: JSON.stringify({
to: 'john@example.com',
subject: 'Hello world',
message: '<h1>Welcome!</h1><p>Thanks for joining us.</p>'
})
});
if (!response.ok) {
throw new Error(`Failed to send email: ${await response.text()}`);
}
console.log(await response.json());
}
sendEmail();
Save as send-email.js and run:
NOTIFY_API_KEY=your_key node send-email.js
The message field accepts plain text or HTML. See Sending Emails for examples of both formats.
Using Node's built-in https module
If you're on an older Node version without global fetch:
const https = require('https');
function sendEmail() {
const data = JSON.stringify({
to: 'john@example.com',
subject: 'Hello world',
message: '<h1>Welcome!</h1><p>Thanks for joining us.</p>'
});
const req = https.request(
{
hostname: 'notify.cx',
path: '/api/email/send',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data),
'x-api-key': process.env.NOTIFY_API_KEY
}
},
(res) => {
let body = '';
res.on('data', (chunk) => (body += chunk));
res.on('end', () => console.log(JSON.parse(body)));
}
);
req.on('error', console.error);
req.write(data);
req.end();
}
sendEmail();