NEWLoisaX CLI 1.4 and 1-command cloud deploys now liveRead post

How to host a WhatsApp bot in Node.js, 24 hours a day

Your WhatsApp bot works on your PC, but stops whenever your computer sleeps. By the end of this guide it runs 24 hours a day on a server, paired once and reconnecting on its own. An upfront note: Baileys is an unofficial WebSocket client — Step 01 explains when the official Meta Cloud API is the better choice.

Aktualisiert am Nov 18, 2026·10 Min. Lesezeit·5 Schritte

Was du in diesem Guide lernst:

  • Entender as diferenças entre a API Oficial da Meta e conexão WebSocket via Baileys.
  • Desenvolver um bot de WhatsApp leve em Node.js sem depender de Chromium.
  • Vincular o número utilizando código de pareamento de 8 dígitos nos logs.
  • Preservar as chaves de sessão em disco para evitar novos pareamentos.
  • Publicar sua aplicação na LoisaX com variáveis de ambiente isoladas.
  • Manter reconexão automática 24/7 em oscilações transitórias de rede.

Download the ready WhatsApp example bot

A Baileys + Node.js 22 bot with pairing-code login, !ping command, session persistence, and automatic reconnect.

Schritt 01

Pick your path before writing code

The official **WhatsApp Business Cloud API** from Meta uses HTTPS webhooks, requires business verification, and bills per conversation template with zero ban risk. **Baileys** connects directly as a linked WebSocket device without Chromium overhead — lightweight for internal tools, provided you avoid bulk spam.

Schritt 02

Use Baileys, which needs no headless browser

Browser-based libraries launch full Chromium instances exceeding 700 MB of RAM. @whiskeysockets/baileys speaks WebSocket natively inside 128 MB–256 MB of RAM.

1{
2 "name": "meu-bot-whatsapp",
3 "version": "1.0.0",
4 "private": true,
5 "type": "module",
6 "main": "src/bot.js",
7 "scripts": {
8 "start": "node src/bot.js"
9 },
10 "engines": {
11 "node": ">=22"
12 },
13 "dependencies": {
14 "@whiskeysockets/baileys": "^6.7.16",
15 "pino": "^9.6.0"
16 }
17}

Schritt 03

Pair cleanly via WA_PAIRING_NUMBER

Set WA_PAIRING_NUMBER in your application variables so an 8-character pairing code prints cleanly in your live logs.

Schritt 04

Build the ZIP without your local session folder

Exclude data/wa-session when packaging your project so production generates a clean, conflict-free device session.

Schritt 05

Reconnect automatically unless explicitly logged out

Checking DisconnectReason.loggedOut ensures transient socket resets reconnect within seconds without asking for a new QR.

Schritt 06

Fehler aufgetreten? Die häufigsten Ursachen & Lösungen

Repeated 401 loggedOut disconnect loop

Ursache: Session unlinked on the phone or shared simultaneously with your local laptop.

Lösung: Clear data/wa-session once and pair exclusively from the server.

Schritt 07

Häufig gestellte Fragen

256 MB to 512 MB handles text commands and media forwarding smoothly.

Community & Weiterbildung

Unser Engagement für Entwickler

Wir bei LoisaX sind überzeugt, dass unsere Aufgabe über Hosting und Cloud-Computing hinausgeht. Wir möchten aktiv zum Lernen und zur Weiterentwicklung unserer Community beitragen.

Deshalb erweitern wir unseren Guide-Katalog fortlaufend um neue Inhalte zu Programmiersprachen, API-Integrationen, Automatisierung und Anwendungsentwicklung.

Weitere Praxisanleitungen

Alle Guides