Saltar al contenido principal

CLI Reference

create

Creates a new Express.js project with interactive prompts.

npx xpress-generator create [name]

Arguments

ArgumentRequiredDescription
nameNoProject name in PascalCase. If omitted, the CLI will ask.

Interactive prompts

PromptTypeOptions
Project nameInputAny PascalCase string
DatabaseListMongoDB · MySQL · PostgreSQL · SQLServer
Use TypeScript?ConfirmYes / No (default: No)
Save locationListCurrent directory (.) · Desktop · Downloads · Documents · Custom path
Scaffold into the current folder

The first location option — "Ruta actual (.)" — creates the project inside whatever directory you're already in. Perfect for CI, monorepos, or when you've pre-created a folder.

Examples

# Interactive — prompts all questions
npx xpress-generator create

# Skip name prompt
npx xpress-generator create BlogApi

# Create a TypeScript project (prompts for DB and location)
npx xpress-generator create MyService

What it generates

src/
shared/errors/AppError.js
shared/utils/catchAsync.js
shared/utils/httpResponse.js
shared/constants/httpStatus.js
shared/constants/messages.js
shared/validators/validate.js
shared/validators/exampleSchema.js
middleware/auth.js
middleware/errorHandler.js
modules/{name}/controller.js
modules/{name}/routes.js
modules/{name}/{name}Model.js
modules/{name}/service.js
modules/auth/authController.js
modules/auth/authRoutes.js
modules/auth/RefreshToken.js
config/config-{db}.js
app.js
server.js
db/
migrations/{timestamp}-create-{name}.js (MySQL / PostgreSQL)
migrations/{timestamp}-create-{name}.sql (SQL Server)
migrate.js (SQL Server)
seeders/ (MySQL / PostgreSQL)
tests/
setup.js
indexController.test.js
.env
.eslintrc.json
.lintstagedrc.json
.sequelizerc (MySQL / PostgreSQL)
src/config/sequelize.js (MySQL / PostgreSQL)
jest.config.js
Dockerfile
docker-compose.yml
.dockerignore
.husky/pre-commit
.xpress.json
package.json
tsconfig.json (TypeScript only)

Installed dependencies

Production:

express dotenv colors cors helmet morgan
bcryptjs jsonwebtoken zod express-rate-limit cookie-parser
+ DB driver (mongoose / mysql2+sequelize / pg+sequelize / mssql)

Dev — runtime:

nodemon
+ TypeScript: ts-node typescript @types/node @types/express @types/*

Dev — testing:

jest supertest eslint lint-staged
+ TypeScript: ts-jest @types/jest @types/supertest

Dev — git hooks:

husky

Dev — migrations:

sequelize-cli (MySQL / PostgreSQL only)

Generated package.json scripts

ScriptDescription
npm run devnodemon (JS) or ts-node (TS)
npm startProduction server
npm testJest with coverage
npm run test:watchJest in watch mode
npm run buildCompile TypeScript (TS only)
npm run db:migrateRun pending migrations (relational DBs)
npm run db:migrate:undoRoll back last migration (MySQL / PostgreSQL)

generate:model

Generates a full CRUD module inside an existing xpress-generator project.

npx xpress-generator generate:model <name>
npx xpress-generator g:model <name>

Arguments

ArgumentRequiredDescription
nameYesModel name in PascalCase (e.g. Product, BlogPost)

Generated files

All files are generated inside src/modules/{name}/:

FileDescription
src/modules/{name}/{name}Model.jsDatabase model for your project's DB
src/modules/{name}/service.jsgetAll, getById, create, update, remove
src/modules/{name}/schema.jsZod validation schema
src/modules/{name}/controller.jsCRUD controller using catchAsync
src/modules/{name}/routes.jsExpress router with auth-protected routes
db/migrations/{ts}-create-{name}.jsSequelize migration (MySQL / PostgreSQL)
db/migrations/{ts}-create-{name}.sqlSQL migration (SQL Server)

How it detects DB and language

The command reads .xpress.json in the project root:

{
"dbType": "MongoDB",
"language": "javascript",
"version": "1.0.0"
}

If .xpress.json is not found, the CLI will ask you to specify the database.

Example

cd MyApp
npx xpress-generator generate:model Product

Output:

✓ src/modules/product/productModel.js
✓ src/modules/product/service.js
✓ src/modules/product/schema.js
✓ src/modules/product/controller.js
✓ src/modules/product/routes.js
✓ db/migrations/1712345678-create-product.js

📌 Run migrations:
npm run db:migrate

📌 Register the route in src/app.js:
const productRoutes = require('./modules/product/routes');
app.use('/api/products', productRoutes);

Generated route permissions

MethodRouteMiddleware
GET/api/productsPublic
GET/api/products/:idPublic
POST/api/productsverifyToken
PUT/api/products/:idverifyToken
DELETE/api/products/:idverifyToken + requireRole('admin')

generate:middleware

Generates a custom Express middleware.

npx xpress-generator generate:middleware <name>
npx xpress-generator g:middleware <name>

Arguments

ArgumentRequiredDescription
nameYesMiddleware name in camelCase (e.g. cache, requestLogger)

Generated file

src/middleware/{name}.js

Example

npx xpress-generator g:middleware cache
# generates: src/middleware/cache.js

Generated content:

const AppError = require('../shared/errors/AppError');

/**
* cache middleware
* Add your logic here
*/
module.exports = (req, res, next) => {
try {
// TODO: implement cache logic
next();
} catch (err) {
next(new AppError(err.message, 500));
}
};

Global options

FlagDescription
--version / -VPrint xpress-generator version
--help / -hShow help for a command
npx xpress-generator --version
npx xpress-generator create --help