How to Integrate WhatsApp into Your Node.js App
How to Integrate WhatsApp into Your Node.js App
WhatsApp has over 2 billion active users, making it the most direct channel you can add to your application. Whether you're building order notifications, a customer support bot, or automated alerts, getting WhatsApp messages into your Node.js app is now a matter of a few API calls, not weeks of waiting for Meta approval.
In this guide you'll learn how to send WhatsApp messages from both a plain Node.js script using ChatBreez — a developer-first WhatsApp API with no per-message fees and no template approval process.
What You'll Need
- A ChatBreez account
- Your API key from the ChatBreez dashboard
- A WhatsApp number paired via QR code in the dashboard
- Node.js 18+ installed
Step 1: Pair Your WhatsApp Number
After signing up, open the ChatBreez dashboard, navigate to instances and click Add instance. Scan the QR code with your WhatsApp mobile app (the same way you'd connect WhatsApp Web). Your number will appear as Connected within a few seconds.
You only need to do this once. After pairing, your number stays connected even if you close the browser.
Step 2: Grab Your API Key
Navigate to API Key and copy your key. Keep it out of your source code store it as an environment variable.
# .env
CHATBREEZ_API_KEY=your_api_key_here
Step 3: Send a Message from Node.js
Install axios (or use the built-in fetch available in Node 18+):
npm install axios
Create a file called send-whatsapp.js:
const axios = require('axios');
const options = {
method: 'POST',
url: 'https://api.chatbreez.com/whatsapp/send-text/my-instance-name',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.CHATBREEZ_API_KEY
},
data: {
recipient: '254123456789', // international format, no + sign
text: 'Hello from ChatBreez!'
}
};
axios.request(options)
.then(response => console.log('Sent:', response.data))
.catch(error => console.error('Error:', error.response?.data || error.message));
Run it:
node send-whatsapp.js
If your number is paired correctly you'll see a success response and the message will arrive on the recipient's WhatsApp within a second or two.
Phone number format: Always use the international format without the
+prefix. For a Kenyan number+254 712 345 678, pass254712345678.
Using Native fetch (Node 18+)
If you'd rather skip axios, Node 18's built-in fetch works just as well:
const response = await fetch('https://chatbreez.com/api/send-message', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.CHATBREEZ_API_KEY
},
body: JSON.stringify({
recipient: '254123456789',
text: 'Hello from ChatBreez!'
})
});
const data = await response.json();
console.log(data);
Sending Rich Media
ChatBreez supports more than plain text. Here's how to send an image:
const axios = require('axios');
const sendMedia = async () => {
try {
const response = await axios.post('https://api.chatbreez.com/whatsapp/send-media/my-instance', {
recipient: '254123456789',
mediatype: 'image',
mimetype: 'image/jpeg',
caption: 'Hello with an image!',
media: 'https://example.com/image.jpg',
fileName: 'image.jpg'
}, {
headers: {
'X-API-Key': 'your_api_key'
}
});
console.log(response.data);
} catch (error) {
console.error(error);
}
};
sendMedia();
Supported types: image, video, audio, document.
Environment Variable Checklist
Make sure your .env (for Node.js) contains:
CHATBREEZ_API_KEY=your_api_key_here
And that it's in your .gitignore:
echo ".env.local" >> .gitignore
echo ".env" >> .gitignore
Never commit API keys to a public repository.
Common Errors & Fixes
| Error | Likely cause | Fix |
|---|---|---|
401 Unauthorized | Wrong or missing API key | Check X-API-Key header matches dashboard key |
400 Bad Request | Invalid phone format | Use international format without +, e.g. 254712345678 |
Session not found | Number not paired | Reconnect via QR code in the dashboard |
| Message not delivered | Number logged out on phone | Re-pair the number in the dashboard |
Summary
Integrating WhatsApp into a Node.js app with ChatBreez comes down to three things: pair your number, store your API key securely, and make a POST request. No Meta Business approval, no per-message fees, no complex SDK just a REST API that works in any JavaScript environment.
The full API reference is available at docs.chatbreez.com.