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

create-express-mongo-ts

v1.5.0

Published

Create Express + MongoDB applications with TypeScript, authentication, and best practices out of the box

Downloads

728

Readme

create-express-mongo-ts

Create Express + MongoDB applications with TypeScript, authentication, and best practices out of the box.

npm version License: MIT

Quick Start

npx create-express-mongo-ts my-app
cd my-app
npm install
cp .env.example .env
npm run dev

What's Included

This template provides a production-ready Express.js + MongoDB setup with:

🔐 Authentication & Security

  • JWT-based authentication (access & refresh tokens)
  • API key management
  • Role-based access control (RBAC)
  • Password hashing with bcrypt
  • Helmet.js security headers
  • CORS configuration

📁 Project Structure

my-app/
├── src/
│   ├── app.ts              # Express app setup
│   ├── config.ts           # Environment configuration
│   ├── index.ts            # Application entry point
│   ├── core/               # Core utilities
│   │   ├── ApiError.ts     # Custom error classes
│   │   ├── ApiResponse.ts  # Standardized API responses
│   │   ├── asyncHandler.ts # Async error handling wrapper
│   │   ├── authUtils.ts    # Authentication utilities
│   │   ├── jwtUtils.ts     # JWT token utilities
│   │   ├── logger.ts       # Winston logger setup
│   │   └── utils.ts        # General utilities
│   ├── database/           # Database layer
│   │   ├── index.ts        # MongoDB connection
│   │   ├── models/         # Mongoose models
│   │   └── repositories/   # Data access layer
│   ├── helpers/            # Helper functions
│   ├── middlewares/        # Express middlewares
│   ├── routes/             # API routes
│   └── types/              # TypeScript type definitions
├── keys/                   # RSA keys for JWT (generate your own)
├── Dockerfile              # Docker configuration
├── tsconfig.json           # TypeScript configuration
├── jest.config.ts          # Jest testing configuration
└── eslint.config.mts       # ESLint configuration

🛠️ Tech Stack

  • Runtime: Node.js 18+
  • Framework: Express.js 5
  • Database: MongoDB with Mongoose ODM
  • Language: TypeScript
  • Validation: Zod
  • Logging: Winston with daily rotation
  • Testing: Jest
  • Linting: ESLint + Prettier

Available Scripts

| Command | Description | |---------|-------------| | npm run dev | Start development server with hot-reload | | npm run build | Compile TypeScript to JavaScript | | npm start | Build and run production server | | npm test | Run test suite | | npm run lint | Check code for linting errors | | npm run lint:fix | Fix linting errors automatically | | npm run prettier:write | Format code with Prettier |

Environment Variables

Create a .env file based on .env.example:

# Server Configuration
PORT=3000
NODE_ENV=development

# Database Configuration
DB_HOST=localhost
DB_PORT=27017
DB_NAME=myapp
DB_USER=
DB_PASSWORD=
DB_MIN_POOL_SIZE=2
DB_MAX_POOL_SIZE=5

# JWT Configuration
ACCESS_TOKEN_VALIDITY_SEC=3600
REFRESH_TOKEN_VALIDITY_SEC=86400
TOKEN_ISSUER=your-app
TOKEN_AUDIENCE=your-app

# CORS Configuration
ORIGIN_URL=*

# Logging
LOG_DIRECTORY=logs

JWT Keys Setup

For production, generate RSA key pairs for JWT signing:

# Navigate to keys directory
cd keys

# Generate private key
openssl genrsa -out private.pem 2048

# Generate public key
openssl rsa -in private.pem -pubout -out public.pem

API Endpoints

Health Check

  • GET /health - Server health status

Authentication

  • POST /auth/signup - User registration
  • POST /auth/signin - User login
  • POST /auth/signout - User logout
  • POST /auth/token/refresh - Refresh access token

Docker Support

Build and run with Docker:

# Build image
docker build -t my-app .

# Run container
docker run -p 3000:3000 --env-file .env my-app

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT