Node.js is where most open-source WhatsApp tooling lives, so a WhatsApp chatbot in Node.js is the shortest path from idea to a bot that answers. The real decision is the library, because it decides whether you run a headless browser or a socket, and how often an update breaks you.
The libraries, side by side
Figures from GitHub on 2026-11-17.
| library | how it connects | license | stars |
|---|---|---|---|
| Baileys | WebSocket, speaks the WhatsApp Web protocol directly, no browser | MIT | ~11.6k |
| whatsapp-web.js | drives WhatsApp Web inside Chromium (Puppeteer) | Apache 2.0 | ~22.9k |
| venom | browser based, Puppeteer | Apache 2.0 | ~6.6k |
| wppconnect | browser based, Puppeteer | see repo | ~3.5k |
The browser-based ones are easier to reason about (it is literally WhatsApp Web) but cost a Chromium per session, hundreds of MB of RAM. Baileys is light and fast, and it is what most self-hosted gateways use, including WACrew and Evolution API.
A working Baileys bot
import makeWASocket, { useMultiFileAuthState, DisconnectReason } from "baileys";
import qrcode from "qrcode-terminal";
async function start() {
const { state, saveCreds } = await useMultiFileAuthState("auth");
const sock = makeWASocket({ auth: state });
sock.ev.on("creds.update", saveCreds);
sock.ev.on("connection.update", ({ connection, lastDisconnect, qr }) => {
if (qr) qrcode.generate(qr, { small: true });
if (connection === "close") {
const code = lastDisconnect?.error?.output?.statusCode;
if (code !== DisconnectReason.loggedOut) start();
}
});
sock.ev.on("messages.upsert", async ({ messages, type }) => {
if (type !== "notify") return;
for (const m of messages) {
if (m.key.fromMe) continue;
const text = m.message?.conversation ?? m.message?.extendedTextMessage?.text;
if (text?.trim().toLowerCase() === "ping") {
await sock.sendMessage(m.key.remoteJid, { text: "pong" });
}
}
});
}
start();
npm install baileys qrcode-terminal, run it, scan the QR under Linked devices, and send "ping" from another phone.
What comes after the demo
The 30 lines work. The part that takes weeks is everything around them:
- Session and reconnects. Sessions drop, devices get removed, the auth folder must survive restarts.
- History.
messages.upsertonly shows what arrives while you are connected. Searching last week means storing every message yourself. - Media. Voice notes need download and transcription; images and documents need storage.
- IDs. Groups, phone JIDs and the newer LID identifiers for the same person all have to be reconciled.
- Not sounding like a bot. Instant replies, perfect punctuation and the same opening every time are what clients notice.
Or skip writing the bot
If the goal is an AI that answers clients on your number, WACrew already does the parts above: it is an open-source collector on Baileys with a panel, history, transcription and a WhatsApp MCP server, so Claude Code, Codex or Cursor can read and reply without you writing a bot. Replies go through a review that blocks robotic text and leave at a human pace. If you still want your own code, WACrew has a REST API with Bearer tokens (docs), and the Python guide shows it from the client side.
FAQ
Which is better, Baileys or whatsapp-web.js? Baileys if you want a light server with many sessions; whatsapp-web.js if you prefer the behavior of the real web app and can pay a browser per session.
Can I run a Node.js WhatsApp bot on a free host? Free tiers sleep, and a sleeping bot misses messages. Use a small VPS or a platform that keeps the process up.
Is this the official WhatsApp API? No. These libraries connect as a linked device. Use them with people who already talk to you; bulk messaging is what gets numbers banned.
Does WACrew replace Baileys? It uses Baileys under the hood and adds storage, the panel, the MCP server and the API on top.


