Command Palette

Search for a command to run...

22kDiscord

Last edited April 28, 2026

Installation

Setup steps

Verify Node and package manager

node --version
npm --version

If node is missing or outdated, install a current LTS release first.

Initialize project

mkdir my-whatsapp-app
cd my-whatsapp-app
npm init -y

Install dependencies

Install the core library:

Install a terminal QR renderer for local development:

puppeteer is managed by the dependency graph. Only override browser paths in special host environments.

Create baseline script

Create index.js with this setup:

const { Client, LocalAuth } = require('whatsapp-web.js')
const qrcode = require('qrcode-terminal')
 
const client = new Client({
  authStrategy: new LocalAuth(),
})
 
client.on('qr', qr => {
  qrcode.generate(qr, { small: true })
})
 
client.on('authenticated', () => {
  console.log('Authenticated')
})
 
client.on('ready', () => {
  console.log('Ready')
})
 
client.on('message_received', async msg => {
  if (msg.body === '!ping') {
    await msg.reply('pong')
  }
})
 
client.on('disconnected', reason => {
  console.log('Disconnected:', reason)
})
 
client.initialize()

Add scripts in package.json

{
  "scripts": {
    "start": "node index.js",
    "dev": "node index.js"
  }
}

First run

npm start

On first run, scan the QR code with WhatsApp Linked Devices.

Validation

Confirm these checkpoints:

  1. authenticated appears after scanning.
  2. ready appears next.
  3. Sending !ping returns pong.
  4. Restart does not require scanning again.

Common installation issues

Node version mismatch

Symptoms:

  1. Install errors in dependencies.
  2. Runtime errors on startup.

Fix:

  1. Install current LTS.
  2. Remove node_modules and package-lock.json.
  3. Run npm install again.

Browser startup fails on servers

If your host has restricted sandbox settings or no GUI, use Puppeteer args explicitly.

const client = new Client({
  authStrategy: new LocalAuth(),
  puppeteer: {
    args: ['--no-sandbox', '--disable-setuid-sandbox'],
  },
})

QR code is not displayed

  1. Verify that the process is still running.
  2. Verify terminal rendering capability.
  3. Add explicit logs inside the qr handler.