npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

natureco-whatsapp-service

v1.0.1

Published

NatureCo WhatsApp Integration Service with Baileys

Readme

NatureCo WhatsApp Service

Standalone Node.js service for WhatsApp integration using whatsapp-web.js. Designed to be deployed on Railway, Render, or any Node.js hosting platform.

Features

  • QR Code Generation - Real-time QR code streaming via SSE
  • Session Management - Multiple bot sessions with LocalAuth
  • Status Monitoring - Check connection status for any session
  • Graceful Disconnect - Clean session termination
  • Production Ready - Optimized for Railway/Render deployment

API Endpoints

POST /connect

Create a new WhatsApp session and generate QR code.

Request:

{
  "bot_id": "bot_123"
}

Response:

{
  "session_id": "whatsapp_bot_123_1234567890",
  "bot_id": "bot_123",
  "status": "pending",
  "message": "WhatsApp session created. Use SSE endpoint to receive QR code.",
  "sse_endpoint": "/qr/whatsapp_bot_123_1234567890"
}

GET /qr/:session_id

Server-Sent Events (SSE) endpoint for real-time QR code streaming.

Events:

  • connected - Initial connection established
  • qr - QR code generated (base64 data URL)
  • ready - WhatsApp authenticated and ready
  • error - Authentication or connection error
  • disconnected - Session disconnected

Example:

const eventSource = new EventSource('https://whatsapp.natureco.me/qr/session_id');

eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data);
  
  if (data.type === 'qr') {
    // Display QR code: data.qr (base64 data URL)
    console.log('QR Code:', data.qr);
  }
  
  if (data.type === 'ready') {
    console.log('WhatsApp connected!');
    eventSource.close();
  }
};

GET /status/:session_id

Get current status of a WhatsApp session.

Response:

{
  "session_id": "whatsapp_bot_123_1234567890",
  "bot_id": "bot_123",
  "status": "connected",
  "created_at": "2024-01-01T00:00:00.000Z",
  "connected_at": "2024-01-01T00:01:00.000Z",
  "disconnected_at": null,
  "has_qr": true,
  "client_active": true,
  "error": null,
  "disconnect_reason": null
}

Status values:

  • pending - Waiting for QR scan
  • authenticated - QR scanned, authenticating
  • connected - Fully connected and ready
  • disconnected - Session ended
  • auth_failed - Authentication failed
  • error - Error occurred

POST /disconnect

Disconnect and destroy a WhatsApp session.

Request:

{
  "session_id": "whatsapp_bot_123_1234567890"
}

Response:

{
  "success": true,
  "message": "WhatsApp session disconnected",
  "session_id": "whatsapp_bot_123_1234567890"
}

GET /sessions

List all active sessions (admin endpoint).

Response:

{
  "total": 2,
  "sessions": [
    {
      "session_id": "whatsapp_bot_123_1234567890",
      "bot_id": "bot_123",
      "status": "connected",
      "created_at": "2024-01-01T00:00:00.000Z",
      "connected_at": "2024-01-01T00:01:00.000Z"
    }
  ]
}

Installation

# Install dependencies
npm install

# Copy environment file
cp .env.example .env

# Start development server
npm run dev

# Start production server
npm start

Environment Variables

PORT=3000
NODE_ENV=production
API_SECRET=your-secret-key-here

Deployment

Railway

  1. Create new project on Railway
  2. Connect GitHub repository
  3. Set environment variables
  4. Deploy automatically

railway.json:

{
  "$schema": "https://railway.app/railway.schema.json",
  "build": {
    "builder": "NIXPACKS"
  },
  "deploy": {
    "startCommand": "npm start",
    "restartPolicyType": "ON_FAILURE",
    "restartPolicyMaxRetries": 10
  }
}

Render

  1. Create new Web Service
  2. Connect GitHub repository
  3. Build Command: npm install
  4. Start Command: npm start
  5. Set environment variables
  6. Deploy

render.yaml:

services:
  - type: web
    name: natureco-whatsapp
    env: node
    buildCommand: npm install
    startCommand: npm start
    envVars:
      - key: NODE_ENV
        value: production

Custom Domain

Point whatsapp.natureco.me to your deployment:

Railway: Settings → Networking → Custom Domain Render: Settings → Custom Domain

Architecture

┌─────────────────┐
│   NatureCo CLI  │
│   or Worker     │
└────────┬────────┘
         │
         │ HTTP/SSE
         ▼
┌─────────────────────────┐
│  WhatsApp Service       │
│  (Express + SSE)        │
└────────┬────────────────┘
         │
         │ whatsapp-web.js
         ▼
┌─────────────────────────┐
│  WhatsApp Web           │
│  (Puppeteer + Chrome)   │
└─────────────────────────┘

Production Considerations

  1. Memory: WhatsApp sessions use ~200-300MB each (Chromium)
  2. Storage: LocalAuth stores session data in .wwebjs_auth/
  3. Scaling: Use Redis for session storage in multi-instance setup
  4. Monitoring: Add health checks and logging (e.g., Sentry)
  5. Security: Add API authentication middleware

Troubleshooting

QR Code not generating:

  • Check Puppeteer dependencies are installed
  • Ensure sufficient memory (min 512MB)
  • Check logs for Chromium errors

Session disconnects:

  • WhatsApp Web sessions expire after ~2 weeks of inactivity
  • Implement reconnection logic in your application

Multiple instances:

  • Use shared storage (S3, Redis) for .wwebjs_auth/
  • Implement session locking to prevent conflicts

License

MIT © NatureCo


Service URL: https://whatsapp.natureco.me Version: 1.0.0 Node.js: >=18.0.0