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

authosphere-nodejs

v2.0.0

Published

Complete authentication solution with database integration for Node.js applications

Readme

🔐 Authosphere Node.js Module

Plug-and-play authentication module for Node.js applications with database integration support.

License: MIT Node.js npm

✨ Features

  • 🔑 JWT Authentication - Secure token-based authentication
  • 🌐 OAuth Integration - Google, GitHub, and more OAuth providers
  • Plug-and-Play - Minimal configuration required
  • 🛡️ Security First - Rate limiting, CORS, Helmet protection
  • 🗄️ Database Integration - MongoDB, PostgreSQL, Redis support
  • 🔄 Hybrid Storage - Primary storage + Redis caching
  • 📊 Health Monitoring - Built-in health checks and monitoring
  • 🎯 TypeScript Ready - Full TypeScript support
  • 📚 Comprehensive Examples - Complete working examples

🚀 Quick Start

Installation

npm install @authosphere/nodejs-auth-module

Basic Usage

const { createAuthosphere } = require('@authosphere/nodejs-auth-module');
const express = require('express');

const app = express();

// Configure Authosphere
const authosphere = createAuthosphere({
  jwtSecret: 'your-super-secret-jwt-key',
  storage: {
    type: 'mongodb', // or 'postgresql', 'redis', 'memory'
    options: {
      uri: 'mongodb://localhost:27017/authosphere'
    }
  },
  oauth: {
    google: {
      clientId: 'your-google-client-id',
      clientSecret: 'your-google-client-secret'
    }
  }
});

// Use Authosphere middleware
app.use('/auth', authosphere);

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

🗄️ Storage Types

In-Memory Storage (Default)

const app = createAuthosphere({
  storage: {
    type: 'memory'
  }
});

MongoDB Storage

const app = createAuthosphere({
  storage: {
    type: 'mongodb',
    options: {
      uri: 'mongodb://localhost:27017/authosphere'
    }
  }
});

PostgreSQL Storage

const app = createAuthosphere({
  storage: {
    type: 'postgresql',
    options: {
      databaseUrl: 'postgresql://user:pass@localhost:5432/authosphere'
    }
  }
});

Redis Storage

const app = createAuthosphere({
  storage: {
    type: 'redis',
    options: {
      url: 'redis://localhost:6379'
    }
  }
});

Hybrid Storage (PostgreSQL + Redis)

const app = createAuthosphere({
  storage: {
    primary: {
      type: 'postgresql',
      options: {
        databaseUrl: 'postgresql://user:pass@localhost:5432/authosphere'
      }
    },
    cache: {
      type: 'redis',
      options: {
        url: 'redis://localhost:6379'
      }
    }
  }
});

🔧 Configuration

Environment Variables

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-in-production

# Database Configuration
MONGODB_URI=mongodb://localhost:27017/authosphere
DATABASE_URL=postgresql://user:pass@localhost:5432/authosphere
REDIS_URL=redis://localhost:6379
STORAGE_TYPE=mongodb

# OAuth Providers
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# Frontend URL
FRONTEND_URL=http://localhost:3000

Configuration Options

const app = createAuthosphere({
  // Server Configuration
  port: 3000,
  host: 'localhost',
  
  // JWT Configuration
  jwtSecret: 'your-super-secret-jwt-key',
  
  // Storage Configuration
  storage: {
    type: 'mongodb',
    options: {
      uri: 'mongodb://localhost:27017/authosphere'
    }
  },
  
  // OAuth Configuration
  oauth: {
    google: {
      clientId: 'your-google-client-id',
      clientSecret: 'your-google-client-secret'
    }
  },
  
  // Security Configuration
  rateLimitMax: 100,
  bcryptRounds: 12,
  
  // Frontend Configuration
  frontendUrl: 'http://localhost:3000'
});

📋 API Endpoints

Authentication

  • POST /register - Register new user
  • POST /login - User login
  • POST /logout - User logout
  • POST /refresh - Refresh JWT token
  • GET /profile - Get user profile

OAuth

  • GET /oauth/:provider/authorize - Start OAuth flow
  • GET /oauth/:provider/callback - OAuth callback
  • GET /oauth/providers - Get available providers

User Management

  • GET /users - Get all users (admin)
  • DELETE /users/me - Delete current user

System

  • GET /health - Health check

🛡️ Security Features

  • JWT Tokens - Secure token-based authentication
  • Password Hashing - bcrypt with configurable rounds
  • Rate Limiting - Configurable request limits
  • CORS Protection - Configurable CORS policies
  • Helmet Security - Security headers
  • Input Validation - Joi schema validation
  • SQL Injection Protection - Parameterized queries
  • XSS Protection - Input sanitization

📊 Health Monitoring

Health Check Endpoint

curl http://localhost:3000/auth/health

Response

{
  "status": "healthy",
  "timestamp": "2023-01-01T00:00:00.000Z",
  "storage": {
    "status": "healthy",
    "type": "mongodb",
    "initialized": true,
    "connection": "connected",
    "stats": {
      "users": 150,
      "sessions": 25,
      "oauthStates": 3,
      "refreshTokens": 45
    }
  }
}

🧪 Testing

Unit Tests

npm test

Integration Tests

npm run test:integration

Load Testing

npm run test:load

📚 Examples

Basic Example

const { createAuthosphere } = require('@authosphere/nodejs-auth-module');

const app = createAuthosphere({
  jwtSecret: 'secret',
  storage: { type: 'memory' }
});

app.listen(3000);

MongoDB Example

const { createAuthosphere } = require('@authosphere/nodejs-auth-module');

const app = createAuthosphere({
  jwtSecret: 'secret',
  storage: {
    type: 'mongodb',
    options: {
      uri: 'mongodb://localhost:27017/authosphere'
    }
  }
});

app.listen(3000);

Hybrid Storage Example

const { createAuthosphere } = require('@authosphere/nodejs-auth-module');

const app = createAuthosphere({
  jwtSecret: 'secret',
  storage: {
    primary: {
      type: 'postgresql',
      options: {
        databaseUrl: 'postgresql://user:pass@localhost:5432/authosphere'
      }
    },
    cache: {
      type: 'redis',
      options: {
        url: 'redis://localhost:6379'
      }
    }
  }
});

app.listen(3000);

🔄 Migration from v1

See Migration Guide for detailed migration instructions.

Quick Migration

// Before (v1)
const app = createAuthosphere({
  jwtSecret: 'secret'
});

// After (v2)
const app = createAuthosphere({
  jwtSecret: 'secret',
  storage: {
    type: 'mongodb',
    options: {
      uri: 'mongodb://localhost:27017/authosphere'
    }
  }
});

📖 Documentation

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

📞 Support

🙏 Acknowledgments


Made with ❤️ by Terekhin Digital Crew