Command line tool which generates production-ready express templates with TypeScript baked in. Spin up a web server in seconds that follows the TypeScript best practices.
express-generator-typescript creates a new Express application similar to the classic express-generator package, but the generated project is fully wired for TypeScript. You get strict typing, linting, hot reloading, production builds, testing utilities, and sane defaults that focus on APIs (no view engine or opinionated ORM). Path aliases are preconfigured through tsconfig-paths and _moduleAliases, so referencing modules stays clean even as the app grows.
***
- TypeScript first – Sensible but minimal tsconfig defaults so you can start development right away.
- Productivity tooling – cross-platform friendly, configures hot-reloading, browser refreshing, linting/formatting, and production building.
- Path aliases – aliases configured in
tsconfig.jsonso you can import modules cleanly. - Keeps dependencies lean – no bundled ORM or UI layers; only the essentials for Express + TS development.
***
npx express-generator-typescript
# or install globally
npm install -g express-generator-typescript
***
# generate a project (defaults to express-gen-ts)
npx express-generator-typescript my-api
cd my-api
# start the server in development mode
npm run devUse --use-yarn if you prefer Yarn over npm. If you omit the project name, the generator creates express-gen-ts.
***
| Option | Description |
|---|---|
project name |
Folder to create. Defaults to express-gen-ts if omitted. |
--use-yarn |
Installs dependencies with Yarn instead of npm. |
The historical
--with-authswitch was removed in v2.5+. For an auth-ready example see the express-jsonwebtoken-demo project.
***
The generated template is a CRUD app for the User record to demonstrate model, services, and routing patterns in Express + TypeScript. Commands for linting, transpiling, formatting, and hot-reloading are all configured for you.
npm run dev– Run the server in dev mode with live reload and browser refresh.npm run test- Run tests with vitest.npm run test -- users.test.ts– Target a single test file.npm run lint– Run ESLint checks.npm run format- Run prettier.npm run build– Compile the project for production.npm start– Serve the built project.npm run type-check– Run the TypeScript compiler without emitting files.
Because this is a small CRUD app, layered is the architectural pattern of choice. However, you should consider switching to a domain-based layout if you plan on scaling. There is a good tutorial here in the Typescript Best Practices README about architectural patterns with TypeScript.
Layers explained:
- src/ <-- source code
- common/
- constants/
- Paths.ts <-- Single source of truth for all API routes
- routes/ <-- extracting and validating values from express Request/Response objects
- services/ <-- Business logic (where everything comes together)
- repos/ <-- Talking to the database layer
- models/ <-- For describing/handling objects representing database records
- tests/ <-- unit-tests
***
The generated template uses eslint+prettier, so if you want features like formatting on save, you need to make sure to install the prettier extension for VSCode and set it as your default formatter in .vscode/setting.json:
// .vscode/settings.json
{
"editor.minimap.enabled": false,
"editor.rulers": [80],
"editor.tabSize": 2,
"workbench.sideBar.location": "right",
"workbench.editor.empty.hint": "hidden",
// Formatting: Prettier only
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
// ESLint: linting only (NO formatting)
"eslint.format.enable": false,
"eslint.nodePath": "node_modules",
"eslint.validate": ["javascript", "typescript", "typescriptreact"],
// Run ESLint fixes (non-formatting) on save
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
// Language overrides (keep Prettier)
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// JSDoc noise reduction
"javascript.suggest.completeJSDocs": false,
"javascript.suggest.jsdoc.generateReturns": false,
"typescript.suggest.completeJSDocs": false,
"typescript.suggest.jsdoc.generateReturns": false
}If you want to debug in VSCode with breakpoints you need to start the processes through .vscode/launch.json:
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Dev - ts-node",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev"],
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal"
},
{
"name": "Test - Vitest",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "test"],
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal"
}
]
}
***
MIT © seanpmaxwell1
