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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sangtran13/ecommerce-api

v1.5.0

Published

A production-ready RESTful API for e-commerce applications built with Node.js, Express.js, MongoDB, and Redis.

Readme

🛒 Ecommerce API

A production-ready RESTful API for e-commerce applications built with Node.js, Express.js, MongoDB, and Redis.

✨ Features

  • JWT Authentication with Redis token blacklisting
  • Role-based Access Control (User, Manager, Admin)
  • Complete Product Management (Categories, Sub-categories, Brands, Products)
  • Image Upload & Processing with Sharp
  • Search, Filter & Pagination
  • Email Service with Gmail SMTP
  • Docker Support with docker-compose

🛠️ Tech Stack

  • Backend: Node.js 18+, Express.js 5.1.0
  • Database: MongoDB with Mongoose
  • Cache: Redis for session management
  • Authentication: JWT with refresh tokens
  • File Upload: Multer + Sharp
  • Email: Nodemailer
  • DevOps: Docker, AWS ECR

📋 Prerequisites

  • Node.js 18+ and npm
  • MongoDB (local or Atlas)
  • Redis (local or cloud)
  • Docker & Docker Compose
  • Gmail account with App Password

🚀 Quick Start

# Clone repository
git clone https://github.com/yourusername/ecommerce-api.git
cd ecommerce-api

# Install dependencies
npm install

# Setup environment
cp config.env.example config.env
# Edit config.env with your settings

# Start development server
npm run start:dev

🔧 Environment Variables

NODE_ENV=development
PORT=8000
DB_URI=mongodb://localhost:27017/ecommerce
REDIS_URL=redis://localhost:6379
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=30d
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
[email protected]
EMAIL_PASSWORD=your-gmail-app-password

📚 API Endpoints

Authentication

POST /api/v1/auth/signup      # Register user
POST /api/v1/auth/login       # Login user
POST /api/v1/auth/logout      # Logout user
POST /api/v1/auth/refresh     # Refresh token

Products

GET    /api/v1/products       # Get all products
GET    /api/v1/products/:id   # Get product by ID
POST   /api/v1/products       # Create product (Admin)
PUT    /api/v1/products/:id   # Update product (Admin)
DELETE /api/v1/products/:id   # Delete product (Admin)

Categories

GET    /api/v1/categories     # Get all categories
POST   /api/v1/categories     # Create category (Admin)
PUT    /api/v1/categories/:id # Update category (Admin)
DELETE /api/v1/categories/:id # Delete category (Admin)

Query Examples

# Filter by price range
GET /api/v1/products?price[gte]=1000&price[lte]=5000

# Search and sort
GET /api/v1/products?keyword=iphone&sort=-createdAt

# Pagination
GET /api/v1/products?page=2&limit=10

🐳 Docker Deployment

# Quick start with Docker
docker-compose up -d

# View logs
docker-compose logs -f ecommerce-api

# Stop services
docker-compose down

Production with pre-built image

docker run -d \
  --name ecommerce-api \
  -p 8000:8000 \
  -e DB_URI=your_mongodb_uri \
  -e REDIS_URL=your_redis_uri \
  -e JWT_SECRET=your_jwt_secret \
  public.ecr.aws/u9a7t5u9/ecommerce-api:latest

🏗️ Project Structure

ecommerce-api/
├── config/           # Database & Redis configuration
├── middlewares/      # Express middlewares
├── models/           # MongoDB schemas
├── routes/           # API routes
├── services/         # Business logic
├── utils/            # Utilities & validators
├── uploads/          # File upload directory
├── docker-compose.yml
├── Dockerfile
└── server.js         # Entry point

🧪 Testing

# Health check
curl http://localhost:8000/health

# Register user
curl -X POST http://localhost:8000/api/v1/auth/signup \
  -H "Content-Type: application/json" \
  -d '{"name":"Test","email":"[email protected]","password":"password123","passwordConfirm":"password123"}'

# Login
curl -X POST http://localhost:8000/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","password":"password123"}'

🚀 Production Deployment

Cloud Platforms

  • Railway: Connect GitHub → Add env vars → Deploy
  • Heroku: heroku create app-name → Set config vars → Deploy
  • AWS ECS: Use ECR image public.ecr.aws/u9a7t5u9/ecommerce-api:latest

Environment Setup

NODE_ENV=production
DB_URI=mongodb+srv://user:[email protected]/ecommerce
REDIS_URL=redis://default:password@host:port
JWT_SECRET=super-secure-production-secret-key

📄 License

ISC License


Built with ❤️ using Node.js, Express.js, MongoDB, Redis, and Docker