- FAQ
- Introduction
- Comparisons
- Quick Start
- Features
- Disclaimer
- Requirements
- Event Handler
- Command Handler
- Messages
- Chats
- Groups
- Contacts
- Polls
- Channels
- Orders
- Payments
- Multi Device
- Presence and Profile
What Is WWebJS
Setup
Your Application
Components
Business Features
Advanced Topics
Contributing
LocalAuth stores the WhatsApp session in a local folder (.wwebjs_auth by default). After the first login, subsequent restarts restore the session automatically, no QR code needed.
Setup
LocalAuth is built into whatsapp-web.js. No extra packages required.
const { Client, LocalAuth } = require('whatsapp-web.js')
const client = new Client({
authStrategy: new LocalAuth(),
})
client.on('qr', qr => {
console.log('First run, scan this QR code')
})
client.on('ready', () => {
console.log('Ready!')
})
client.initialize()What Gets Created
After the first successful login, a .wwebjs_auth directory appears next to your app file:
app.js
package.json
Add .wwebjs_auth to your .gitignore to avoid accidentally committing session data.
Options
const client = new Client({
authStrategy: new LocalAuth({
clientId: 'my-app', // Unique name — lets multiple apps share one machine
dataPath: './sessions', // Where to store session files (default: ./.wwebjs_auth)
}),
})clientId
When you run more than one app on the same machine, give each a different clientId so their sessions don't overwrite each other:
// app 1
const client1 = new Client({
authStrategy: new LocalAuth({ clientId: 'support-app' }),
})
// app 2
const client2 = new Client({
authStrategy: new LocalAuth({ clientId: 'sales-app' }),
})This creates separate folders: .wwebjs_auth/support-app/ and .wwebjs_auth/sales-app/.
First Run vs Subsequent Runs
First run:
qrevent fires — scan with your phone- Session is saved to disk
authenticatedthenreadyfires
Subsequent runs:
- Session is restored from disk
authenticatedthenreadyfires — no QR code
client.on('qr', qr => {
// This only fires on first run (or if session expires)
console.log('Scan QR code')
})
client.on('ready', () => {
console.log('Ready!')
})Limitations
- One instance per
clientId: Two processes with the sameclientIdwill conflict. - Tied to the filesystem: Moving the app to a different server means copying the session folder.
- Not suitable for containers: If the container is recreated, the session is lost. Use RemoteAuth instead.