Registry / database / baileys-database

baileys-database

JSON →
library1.0.1jsnpmunverified

An adapter for @whiskeysockets/baileys that stores WhatsApp authentication state in MySQL or MongoDB. Version 1.0.1 provides automatic configuration via .env file, supports multiple sessions per database, and returns { state, saveCreds, db }. Released under MIT. Differentiator: database-driven persistence allows multiple bot instances sharing one DB, with simple env-based setup.

npm install baileys-database
INSTALL
IMPORT
SIG · BAILEYS-DATABASE
B
baileys-database
databasejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useDatabaseAuthState
const { useDatabaseAuthState } = require('baileys-database')
const baileysDatabase = require('baileys-database')
Named export only; no default export.
useDatabaseAuthState
import { useDatabaseAuthState } from 'baileys-database'
ESM import supported if project uses ES modules.
db
const { db } = await useDatabaseAuthState()
The returned object also contains a db adapter for manual operations.

Initializes WhatsApp bot with MySQL/MongoDB auth state persistence via .env configuration.

const { default: makeWASocket, DisconnectReason } = require('@whiskeysockets/baileys'); const { useDatabaseAuthState } = require('baileys-database'); async function startBot() { const { state, saveCreds } = await useDatabaseAuthState(); const sock = makeWASocket({ auth: state }); sock.ev.on('creds.update', saveCreds); sock.ev.on('connection.update', (update) => { const { connection, lastDisconnect } = update; if (connection === 'close') { const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut; if (shouldReconnect) startBot(); } }); } startBot();
Debug
Known issues
gotchaDatabase drivers (mysql2 or mongodb) must be installed separately; they are not included as dependencies.
fix
Run: npm install mysql2 or npm install mongodb
affects: >=1.0
gotchaThe session field defaults to 'default'. Using the same session name across bots will share credentials, potentially causing conflicts.
fix
Always set a unique session name per bot instance.
affects: >=1.0
breakingThe function useDatabaseAuthState is async and must be awaited; forgetting await will return a Promise object.
fix
Add await: const { state } = await useDatabaseAuthState();
affects: >=1.0
gotchaEnvironment variables from .env are not automatically loaded by this package; you must use dotenv or similar.
fix
Add require('dotenv').config() at the top of your entry file.
affects: >=1.0
Errors
Common errors & fixes
Cannot find module 'mysql2'
MySQL driver not installed.
fix
npm install mysql2
Cannot find module 'mongodb'
MongoDB driver not installed.
fix
npm install mongodb
TypeError: useDatabaseAuthState is not a function
Incorrect import; likely using default import instead of named import.
fix
Use: const { useDatabaseAuthState } = require('baileys-database')
TypeError: Cannot destructure property 'state' of 'undefined' or 'null'
useDatabaseAuthState was not awaited or returned undefined due to missing config.
fix
Ensure .env is loaded and DB credentials are correct. Add await before useDatabaseAuthState().
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
@whiskeysockets/baileysrequiredPeer dependency; the auth state is consumed by Baileys
mysql2optionalRequired for MySQL driver, optional if using MongoDB
mongodboptionalRequired for MongoDB driver, optional if using MySQL
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
baileys-database — npm install baileys-database · libregistry