express-template-generator
v1.0.10
Published
Node.js template generator
Downloads
317
Maintainers
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.
Table of Contents
- Features
- Installation
- Getting Started
- Language Selection
- Folder Structure
- Built-in Features
- TypeScript Support
- Customization
- Support the Project
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-generatorUsing NPX (No Global Installation Required)
npx express-template-generator my-appThis 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-appYou'll be prompted to choose your preferred language:
? Select language: (Use arrow keys)
❯ JavaScript
TypeScript2. Navigate to Project Directory
cd my-app3. Install Dependencies
npm install4. Start the Application
Production mode:
npm startDevelopment mode (with hot-reload):
npm run devTypeScript build (TypeScript projects only):
npm run buildLanguage 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 (
.jsor.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 templateTypeScript 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:
TypeScript Configuration (
tsconfig.json)- ES2020 target
- CommonJS modules
- Strict type checking
- Source maps for debugging
- Output to
dist/directory
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
Development Tools
typescript- TypeScript compilerts-node- Execute TypeScript directlynodemon- Auto-restart on file changes
Build Scripts
{ "scripts": { "start": "npm run build && node ./dist/bin/www.js", "dev": "nodemon ./bin/www.ts", "build": "tsc" } }
TypeScript Development Workflow
- Development: Use
npm run devto run TypeScript files directly with hot-reload - Build: Use
npm run buildto compile TypeScript to JavaScript indist/ - Production: Use
npm startto 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 applicationnpm run dev- Start with nodemon (auto-reload)
TypeScript Projects
npm start- Build and start the applicationnpm 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:
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
- Author: Sagar Chopda
- Email: [email protected]
- GitHub: @sagarchopda
Happy Coding! 🚀

