connection.update event, which you render however you like — to the terminal, to an image, or to your frontend. Open WhatsApp on your phone, navigate to Linked Devices, and scan the code to complete the link.
Basic setup
1
Install Baileys
If you haven’t already, add Baileys to your project.
2
Create the socket and listen for the QR string
The QR string is delivered through the In production, send the
connection.update event. Use a library like qrcode-terminal (or qrcode for image/canvas output) to render it.qr string to your frontend and render it there instead of in the terminal.3
Scan the QR code
On your phone, open WhatsApp and go to Settings → Linked Devices → Link a Device. Point your camera at the rendered QR code.Once scanned, WhatsApp forcibly disconnects the socket so Baileys can reconnect with full credentials. This is expected — handle it by reconnecting on
DisconnectReason.restartRequired (see Keeping the connection alive).Customizing the browser identity and receiving full history
The browser identity Baileys presents to WhatsApp affects how your client appears in Linked Devices and how much message history is delivered on first sync. Both options are configured via the socket — see Configure the Baileys socket connection for theBrowsers presets and the syncFullHistory flag.
Keeping the connection alive
Baileys maintains a persistent WebSocket connection. If your process exits, the session is lost. Handle theconnection.update event to detect disconnections and reconnect when appropriate.