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

node-express-jwt-project-scaffolding

v1.0.0

Published

A CLI tool to scaffold Node.js + Express + JWT authentication projects

Readme

node-express-jwt-project-scaffolding

A CLI tool that creates a ready-to-use Node.js + Express + JWT authentication project. This is like create-react-app but for backend projects with authentication built-in.

Features

Zero Configuration - Just run one command and get a complete backend project
🔐 JWT Authentication - User registration, login, and token verification ready to use
📁 Clean Architecture - Well-organized folder structure with best practices
🚀 TypeScript Support - Fully typed codebase
💾 TypeORM Integration - Database models and migrations ready
📝 Logging - Winston logger pre-configured
🛡️ Security - Helmet, CORS, and security best practices included
🎯 Role-Based Access - Middleware for role-based authorization

Installation

Install globally using npm:

npm install -g node-express-jwt-project-scaffolding

Or use with npx (no installation needed):

npx node-express-jwt-project-scaffolding my-backend-api

Usage

Create a new project:

node-express-jwt-project-scaffolding my-backend-api

This will create a new directory my-backend-api with all the boilerplate code.

Quick Start

After creating your project:

cd my-backend-api
npm install

Configure Environment Variables

Edit the .env file with your database credentials:

PORT=3000
NODE_ENV=development
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=postgres
DATABASE_PASSWORD=your_password
DATABASE_NAME=myapp_db
JWT_SECRET=your_super_secret_key_change_this
JWT_EXPIRES_IN=1h
JWT_REFRESH_SECRET=your_refresh_secret_key

Start Development Server

npm run dev

Your server will start at http://localhost:3000

Project Structure

my-backend-api/
├── src/
│   ├── app.ts                 # Express app configuration
│   ├── index.ts               # Entry point
│   ├── datasource.ts          # TypeORM configuration
│   ├── routes.ts              # API routes
│   ├── common/
│   │   ├── interceptors/
│   │   │   └── requestLogger.ts
│   │   ├── middlewares/
│   │   │   ├── authMiddleware.ts
│   │   │   ├── errorHandler.ts
│   │   │   ├── logger.middleware.ts
│   │   │   └── roleGuard.ts
│   │   └── utils/
│   │       └── jwt.ts
│   ├── modules/
│   │   ├── auth/
│   │   │   ├── auth.controller.ts
│   │   │   ├── auth.service.ts
│   │   │   └── dto/
│   │   └── users/
│   │       ├── user.entity.ts
│   │       ├── users.controller.ts
│   │       ├── users.service.ts
│   │       └── dto/
│   └── shared/
│       └── utils/
│           ├── customResponse.ts
│           ├── logger.ts
│           └── constants/
├── .env
├── package.json
└── tsconfig.json

API Endpoints

Authentication

Send OTP

POST /api/auth/send-otp
Content-Type: application/json

{
  "mobile": "1234567890"
}

Signup

POST /api/auth/signup
Content-Type: application/json

{
  "mobile": "1234567890",
  "otp": "123456",
  "name": "John Doe",
  "email": "[email protected]"
}

Login

POST /api/auth/login
Content-Type: application/json

{
  "mobile": "1234567890",
  "otp": "123456"
}

Protected Routes

Get User Profile

GET /api/users/profile
Authorization: Bearer <your_access_token>

Available Scripts

  • npm run dev - Start development server with hot reload
  • npm run build - Build TypeScript to JavaScript
  • npm start - Run production server
  • npm run typeorm - Run TypeORM CLI commands

Technologies Used

  • Node.js - Runtime environment
  • Express - Web framework
  • TypeScript - Type-safe JavaScript
  • TypeORM - ORM for database operations
  • PostgreSQL - Database
  • JWT - Authentication tokens
  • Winston - Logging
  • Helmet - Security middleware
  • CORS - Cross-origin resource sharing
  • Morgan - HTTP request logger

Development Notes

OTP Verification

By default, the OTP is printed to the console. For production:

  1. Integrate an SMS provider (Twilio, AWS SNS, etc.)
  2. Replace the console.log in auth.service.ts
  3. Consider using Redis to store OTPs with TTL

Database

The project uses PostgreSQL by default. To use a different database:

  1. Install the appropriate driver
  2. Update datasource.ts with the new configuration

Security Recommendations

  • Change JWT secrets in production
  • Set synchronize: false in TypeORM for production
  • Use environment-specific .env files
  • Enable HTTPS in production
  • Implement rate limiting
  • Add input validation using class-validator

License

MIT

Contributing

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

Support

If you have any questions or issues, please open an issue on GitHub.


Happy Coding! 🚀