How to Host a Lightweight WhatsApp Bot 24/7 (Node.js Baileys Guide)
Traditional Puppeteer/Chromium WhatsApp libraries consume 500–900 MB of RAM just to boot a headless browser. By using @whiskeysockets/baileys (a pure WebSocket implementation of WhatsApp Web Multi-Device), your WhatsApp bot uses only ~55–80 MB RAM — meaning it runs reliably 24/7 even on the Free tier, reconnects automatically, and persists its auth session across restarts.
1. Use Baileys (Pure WebSocket) Instead of Headless Chrome
Always prefer pure WebSocket libraries like @whiskeysockets/baileys or WhatsApp Cloud API webhooks over heavy Chromium wrappers (whatsapp-web.js). If you genuinely need whatsapp-web.js + Puppeteer, choose Developer (2 GB RAM) or Pro (6 GB RAM).
{
"name": "my-whatsapp-bot",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"@whiskeysockets/baileys": "^6.7.16",
"pino": "^9.6.0",
"qrcode-terminal": "^0.12.0"
}
}
2. Persist Auth Credentials & Handle Clean Reconnects
Store auth credentials inside a local ./auth_info folder so your bot never asks you to re-scan the QR code after restarts. Bot Uptime Restore Points automatically back up your auth folder alongside your code.
const { default: makeWASocket, useMultiFileAuthState, DisconnectReason } = require('@whiskeysockets/baileys');
const pino = require('pino');
const qrcode = require('qrcode-terminal');
async function startBot() {
const { state, saveCreds } = await useMultiFileAuthState('./auth_info');
const sock = makeWASocket({
auth: state,
logger: pino({ level: 'silent' }),
printQRInTerminal: false
});
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) startBot();
} else if (connection === 'open') {
console.log('[WhatsApp] Connected 24/7 on Bot Uptime!');
}
});
sock.ev.on('messages.upsert', async ({ messages }) => {
const msg = messages[0];
if (!msg?.message || msg.key.fromMe) return;
const text = msg.message.conversation || msg.message.extendedTextMessage?.text || '';
if (text.trim().toLowerCase() === '!ping') {
await sock.sendMessage(msg.key.remoteJid, { text: 'Pong! Running 24/7 on Bot Uptime.' });
}
});
}
startBot();
3. Stay Safe & Compliant
Bot Uptime strictly prohibits unsolicited bulk messaging, spam blasts, number scraping, or scam automation on WhatsApp or Telegram. Only reply to users who message your bot or groups that explicitly invited it, and enable Auto-Restart in your Bot panel so transient socket drops recover automatically.
- Scan the QR code directly from the Bot Uptime Live Console (or use Baileys phone-number pairing code).
- Never delete ./auth_info unless you want to unlink and re-authenticate your WhatsApp session.
- Enable Auto-Restart + automated Restore Points so your session survives container updates.
Frequently Asked Questions
Can I host the official Meta WhatsApp Cloud API webhook too?
Yes! On Developer and Pro plans, claim an HTTPS subdomain (*.apps.botuptime.net) in the Domains tab and paste the HTTPS webhook URL directly into your Meta App Dashboard.
Why does Puppeteer / whatsapp-web.js crash on 256 MB RAM?
Headless Chromium alone needs 400–600 MB RAM. Use Baileys (~60 MB RAM) on Free, or upgrade to Developer (2 GB RAM) / Pro (6 GB RAM) if you need browser automation.
Ready to deploy your bot 24/7?
Launch a custom Discord, Telegram, or WhatsApp container (Python, Node.js, Java, Rust) with Managed Databases and Free AI Agents — or deploy a ready-made Discord bot in 1 click on Bot Uptime.