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

create-node-backend-ts

v2.3.0

Published

CLI to scaffold a Node.js + TypeScript backend with Express, MongoDB, Mongoose, and full CRUD modules.

Downloads

657

Readme

create-node-backend-ts

A CLI tool to scaffold a complete Node.js + TypeScript backend with modern best practices.

Generate a ready-to-use backend with:

  • Express for HTTP server
  • TypeScript with strict typing
  • MongoDB integration using Mongoose
  • Logging via Winston with daily rotated logs
  • Global Error Handler for centralized error management
  • Async Handler Wrapper to simplify async route handling
  • Environment Configuration via .env files
  • Request Validation using Joi
  • Organized Route / Controller / Service / Model structure

Perfect for rapid backend project setup with minimal boilerplate.


🚀 Installation (No global install needed)

Run the generator using npx:

npx create-node-backend-ts my-backend

Or using yarn:

yarn create node-backend my-backend

Or using pnpm:

pnpm dlx create-node-backend-ts my-backend

my-backend will be the folder name of your new project.

📦 After Generating Project

cd my-backend          # Go into your project folder
npm install            # Install dependencies
npm run dev            # Start the development server

Development mode uses tsx watch (if configured) or ts-node-dev.

Logs will be written to the logs/ folder, with console output only in development.

🗂 Project Structure

Example of the generated backend structure:

my-backend/
├─ logs/                 # Rotated log files
├─ src/
│  ├─ controllers/       # Route handlers
│  ├─ services/          # Business logic
│  ├─ routes/            # API routes
│  ├─ models/            # Mongoose models
│  ├─ middlewares/       # Error handler, async wrapper
│  ├─ utils/             # Logger, helpers, etc.
│  └─ server.ts          # Entry point
├─ package.json
├─ tsconfig.json
├─ .env                  # Environment variables
└─ README.md

⚡ CLI Module Generation

After creating your project, you can generate boilerplate module files for any feature:

npx create-node-backend-ts --generate <module-name>

For example:

npx create-node-backend-ts --generate product

This will automatically create the following files:

src/controllers/product.controller.ts
src/models/product.model.ts
src/services/product.service.ts
src/routes/product.routes.ts

Replace product with any module name to scaffold the boilerplate automatically.

⚙ Features

Global Error Handling

All errors in routes are caught and sent in a structured JSON format.

Async Route Wrapper

Avoid repetitive try-catch blocks in async routes.

Validation with Joi

Request payloads can be validated easily with reusable schemas.

Logging with Winston

  • Daily rotated log files (logs/)
  • Console logging only in development mode

Environment Variables

Load .env files automatically with dotenv.

💡 Tips

  • Add .env for sensitive configs like MONGO_URI, PORT, etc.
  • In production, use file logs only; console logs are for development.
  • Extend controllers, services, models, and routes as needed — template is modular and CLI-assisted.

Use the CLI to generate any module at any time after project creation.