create-express-app-by-kk
v4.3.1
Published
A CLI tool to scaffold a production-ready Express.js + TypeScript application with your choice of database and optional Redis support.
Downloads
552
Readme
create-express-app-by-kk
A CLI tool to scaffold a production-ready Express.js + TypeScript application with your choice of database and optional Redis support.
🚀 What It Does
Runs an interactive prompt asking two questions, then generates a fully wired project:
- Which database? → PostgreSQL (Sequelize) or MongoDB (Mongoose)
- Configure Redis? → Yes / No
Every scaffold includes:
- 📂 Module-based architecture (
modules/Auth,modules/User) - ✨ TypeScript with pre-configured
tsconfig.json - 🔐 JWT authentication + bcrypt password hashing
- ✅ Express-validator for request validation
- ⚙️ Pre-configured
.env.localand.gitignore - 🗄️ Migrations wired to run automatically on
npm run devandnpm start
📦 Installation
npm install -g create-express-app-by-kk🛠️ Usage
npx create-express-app-by-kk <project-name>You will be prompted:
◆ Which database do you want to use?
│ ● PostgreSQL (with Sequelize ORM)
│ ○ MongoDB (with Mongoose ODM)
◆ Do you want to configure Redis?
│ ○ Yes ● No📁 Generated Structure
PostgreSQL (Sequelize)
<project-name>/
├── index.ts # Express entry point + route mounting
├── package.json
├── tsconfig.json
├── .env.local # DB + JWT env vars template
├── .gitignore
├── config/
│ ├── config.js # sequelize-cli config (reads .env.local)
│ ├── database.ts # Sequelize instance + connection check
│ └── redis.ts # (only if Redis selected)
├── interfaces/
│ └── response.interface.ts
├── middlewares/
│ └── validate.ts # validateRequest, isAdmin, isDeveloper
├── migrations/
│ └── <timestamp>-create-user.cjs # Sequelize migration for Users table
├── modules/
│ ├── Auth/
│ │ ├── auth.interface.ts
│ │ ├── auth.validator.ts
│ │ ├── auth.service.ts
│ │ ├── auth.controller.ts
│ │ └── auth.routes.ts
│ └── User/
│ ├── user.model.ts
│ ├── user.service.ts
│ ├── user.controller.ts
│ ├── user.validator.ts
│ └── user.routes.ts
└── utils/
└── helpers.ts # SendResponse, HashPassword, JWT helpersMongoDB (Mongoose)
<project-name>/
├── index.ts # Express entry point + route mounting
├── package.json
├── tsconfig.json
├── migrate-mongo-config.js # migrate-mongo configuration (reads .env.local)
├── .env.local # DB + JWT env vars template
├── .gitignore
├── config/
│ ├── database.ts # Mongoose connect function
│ └── redis.ts # (only if Redis selected)
├── interfaces/
│ └── response.interface.ts
├── middlewares/
│ └── validate.ts # validateRequest, isAdmin, isDeveloper
├── migrations/
│ └── <timestamp>-create-user.js # migrate-mongo migration for users collection
├── modules/
│ ├── Auth/
│ │ ├── auth.interface.ts
│ │ ├── auth.validator.ts
│ │ ├── auth.service.ts
│ │ ├── auth.controller.ts
│ │ └── auth.routes.ts
│ └── User/
│ ├── user.model.ts # Mongoose Schema + IUser interface
│ ├── user.service.ts
│ ├── user.controller.ts
│ ├── user.validator.ts
│ └── user.routes.ts
└── utils/
└── helpers.ts # SendResponse, HashPassword, JWT helpers⚙️ Scripts
PostgreSQL
| Script | Description |
|---|---|
| npm run dev | Runs migrations then starts with nodemon |
| npm run build | Bundles with esbuild → dist/index.js |
| npm start | Runs migrations then starts from dist/ |
| npm run create:migration -- --name <name> | Generate a new Sequelize migration |
| npm run db:migrate | Run all pending Sequelize migrations |
MongoDB
| Script | Description |
|---|---|
| npm run dev | Runs migrations then starts with nodemon |
| npm run build | Bundles with esbuild → dist/index.js |
| npm start | Runs migrations then starts from dist/ |
| npm run create:migration -- <name> | Generate a new migrate-mongo migration |
| npm run db:migrate | Run all pending migrations (up) |
| npm run db:migrate:down | Roll back last migration (down) |
🔑 Environment Variables
PostgreSQL — .env.local
DATABASE=
DATABASE_USERNAME=
DATABASE_PASSWORD=
DATABASE_HOST=
DIALECT=postgres
NODE_ENV="development"
JWT_SECRET=
PORT=4000MongoDB — .env.local
MONGODB_URI=
MONGODB_DB_NAME=
NODE_ENV="development"
JWT_SECRET=
PORT=4000
MONGODB_DB_NAMEis optional — if omitted, the database name from the URI is used.
🔴 Redis (optional)
If you select Yes for Redis, config/redis.ts is added with a pre-configured client including reconnect strategy and event logging.
⚠️ Redis must be installed and running on your server. https://redis.io/docs/getting-started/installation/
🗄️ Migrations
PostgreSQL
Migrations use sequelize-cli and run automatically via the predev / prestart hooks.
The config/config.js file is picked up automatically by sequelize-cli.
MongoDB
Migrations use migrate-mongo. The migrate-mongo-config.js at the project root points to your MONGODB_URI and the migrations/ directory.
Migrations also run automatically via the predev / prestart hooks.
🏗️ After Setup
cd <project-name>
# 1. Fill in your credentials
nano .env.local
# 2. Start the dev server (migrations run automatically)
npm run dev