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

express-template-generator

v1.0.10

Published

Node.js template generator

Downloads

317

Readme

Express Template Generator

A powerful CLI tool to quickly scaffold production-ready Express.js applications with support for both JavaScript and TypeScript. Generate boilerplate code pre-configured with essential features like routing, middleware, template engines, and a clean MVC architecture.

npm version License: MIT

Table of Contents

Features

Express Template Generator helps you build scalable web applications and APIs with:

Language Choice - Generate projects in JavaScript or TypeScript

Predefined Folder Structure - Clean, modular architecture for scalability

Pre-built Middleware - Pagination, logging, and structured responses out of the box

MVC Architecture - Ready-to-use controllers, services, and routes

TypeScript Support - Full TypeScript templates with proper type definitions

EJS Templates - Server-side rendering with EJS view engine

Development Ready - Nodemon integration for hot-reloading

Production Ready - Build scripts and optimized configuration

Installation

You can install the package globally or use npx to generate an Express app without installing it permanently.

Install Globally

npm install -g express-template-generator

Using NPX (No Global Installation Required)

npx express-template-generator my-app

This will create a new Express project inside the my-app folder.

🚀 Getting Started

1. Generate Your Project

Run the generator:

npx express-template-generator my-app

You'll be prompted to choose your preferred language:

? Select language: (Use arrow keys)
❯ JavaScript
  TypeScript

2. Navigate to Project Directory

cd my-app

3. Install Dependencies

npm install

4. Start the Application

Production mode:

npm start

Development mode (with hot-reload):

npm run dev

TypeScript build (TypeScript projects only):

npm run build

Language Selection

When you run the generator, you can choose between JavaScript and TypeScript:

  • JavaScript: Traditional Node.js with CommonJS modules
  • TypeScript: Fully typed codebase with ES modules and TypeScript compiler

The generator will automatically:

  • Set up the appropriate file extensions (.js or .ts)
  • Configure TypeScript compiler if TypeScript is selected
  • Install necessary type definitions (@types/* packages)
  • Set up proper build scripts in package.json

📂 Folder Structure

JavaScript Project Structure

/my-app
├── app.js                  # Main application file
├── bin
│   └── www                 # Server startup script
├── package.json            # Dependencies and scripts
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js            # Home routes
│   ├── users.js            # User routes
│   └── api.js              # API routes
├── controllers
│   ├── index.js            # Home controller
│   └── users.js            # User controller
├── services
│   ├── index.js            # Home service layer
│   └── users.js            # User service layer
├── utility
│   ├── logger.js           # Winston logger
│   ├── messages.js         # Response messages
│   ├── pagination.js       # Pagination middleware
│   ├── response.js         # Response utilities
│   └── responseCode.js     # HTTP status codes
└── views
    ├── error.ejs           # Error page template
    └── index.ejs           # Home page template

TypeScript Project Structure

/my-app
├── app.ts                  # Main application file (TypeScript)
├── tsconfig.json           # TypeScript configuration
├── bin
│   └── www.ts              # Server startup script (TypeScript)
├── dist/                   # Compiled JavaScript output (after build)
├── package.json            # Dependencies and scripts
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.ts            # Home routes (TypeScript)
│   ├── users.ts            # User routes (TypeScript)
│   └── api.ts              # API routes (TypeScript)
├── controllers
│   ├── index.ts            # Home controller (TypeScript)
│   └── users.ts            # User controller (TypeScript)
├── services
│   ├── index.ts            # Home service layer (TypeScript)
│   └── users.ts            # User service layer (TypeScript)
├── utility
│   ├── logger.ts           # Winston logger (TypeScript)
│   ├── messages.ts         # Response messages (TypeScript)
│   ├── pagination.ts       # Pagination middleware (TypeScript)
│   ├── response.ts         # Response utilities (TypeScript)
│   └── responseCode.ts     # HTTP status codes (TypeScript)
└── views
    ├── error.ejs           # Error page template
    └── index.ejs           # Home page template

🔧 Built-in Features

📜 Pagination Middleware

A custom pagination middleware is automatically available in every request as req.pagination.

JavaScript Example:

const list = async (req) => {
    const { limit, skip } = req.pagination;
    return someDatabaseQuery.find().limit(limit).skip(skip);
};

TypeScript Example:

import { Request } from 'express';

const list = async (req: Request): Promise<any[]> => {
    const { limit, skip } = req.pagination;
    return someDatabaseQuery.find().limit(limit).skip(skip);
};

📢 Structured Responses

Built-in response utilities help maintain consistent API responses across your application.

Success Response Example:

return response.sendSuccessResponse(
    req, 
    res, 
    data, 
    responseCode.OK, 
    "Data retrieved successfully"
);

Error Response Example:

return response.sendFailResponse(
    req, 
    res, 
    responseCode.BAD_REQUEST, 
    "Invalid request"
);

📜 Logging Utility

Structured logging system using Winston for better debugging and monitoring.

Example:

const logger = require("./utility/logger");

logger.info("User login successful");
logger.error("Database connection failed");
logger.warn("API rate limit approaching");

TypeScript Example:

import logger from './utility/logger';

logger.info("User login successful");
logger.error("Database connection failed");
logger.warn("API rate limit approaching");

🔷 TypeScript Support

What's Included

When you select TypeScript, the generator automatically sets up:

  1. TypeScript Configuration (tsconfig.json)

    • ES2020 target
    • CommonJS modules
    • Strict type checking
    • Source maps for debugging
    • Output to dist/ directory
  2. Type Definitions

    • @types/node - Node.js types
    • @types/express - Express.js types
    • @types/cookie-parser - Cookie parser types
    • @types/morgan - Morgan logger types
    • @types/debug - Debug utility types
  3. Development Tools

    • typescript - TypeScript compiler
    • ts-node - Execute TypeScript directly
    • nodemon - Auto-restart on file changes
  4. Build Scripts

    {
      "scripts": {
        "start": "npm run build && node ./dist/bin/www.js",
        "dev": "nodemon ./bin/www.ts",
        "build": "tsc"
      }
    }

TypeScript Development Workflow

  1. Development: Use npm run dev to run TypeScript files directly with hot-reload
  2. Build: Use npm run build to compile TypeScript to JavaScript in dist/
  3. Production: Use npm start to build and run the compiled JavaScript

Type Safety Benefits

  • Compile-time error checking - Catch errors before runtime
  • IntelliSense support - Better IDE autocomplete and documentation
  • Refactoring confidence - Safely rename and restructure code
  • Self-documenting code - Types serve as inline documentation

🎨 Customization

The generated structure is flexible and easily customizable:

  • Add Middleware - Integrate CORS, rate limiting, authentication, etc.
  • Extend Controllers - Add new routes and business logic
  • Modify Services - Integrate with databases (MongoDB, PostgreSQL, etc.)
  • Change Response Structures - Customize API response formats
  • Add Validation - Integrate libraries like Joi or express-validator
  • Environment Configuration - Use dotenv for environment variables (already included)

Example: Adding a New Route

JavaScript:

// routes/products.js
const express = require('express');
const router = express.Router();
const productController = require('../controllers/products');

router.get('/', productController.list);
router.post('/', productController.create);

module.exports = router;

TypeScript:

// routes/products.ts
import express, { Router } from 'express';
import * as productController from '../controllers/products';

const router: Router = express.Router();

router.get('/', productController.list);
router.post('/', productController.create);

export default router;

📦 Package Scripts

JavaScript Projects

  • npm start - Start the application
  • npm run dev - Start with nodemon (auto-reload)

TypeScript Projects

  • npm start - Build and start the application
  • npm run dev - Start with ts-node and nodemon (auto-reload)
  • npm run build - Compile TypeScript to JavaScript

🚀 Support the Project

If you find Express Template Generator helpful and would like to support its development:

Buy Me a Coffee

Your support means a lot! If you'd like to show your appreciation, you can buy me a coffee ☕ by visiting the link below:

Buy Me A Coffee

Every contribution helps keep the project alive and encourages further improvements.

📄 License

MIT © Sagar Chopda

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

📧 Contact


Happy Coding! 🚀