create-express-setup
v1.0.2
Published
Interactive CLI for setting up Express projects with TypeScript/JavaScript
Maintainers
Readme
create-express-setup
Interactive CLI tool for scaffolding Express.js projects with TypeScript or JavaScript support.
Features
- Interactive project setup with customizable options
- TypeScript or JavaScript support
- ESM (ECMAScript Modules) or CommonJS module systems
- Professional project structure with organized folders
- Optional ESLint and Prettier configuration
- Environment variables setup with dotenv
- Hot-reload development environment
- Pre-configured build and development scripts
Installation
Install globally to use the CLI anywhere:
npm install -g create-express-setupOr use with npx (no installation required):
npx create-express-setupQuick Start
Run the CLI and follow the interactive prompts:
express-setupOr with npx:
npx create-express-setupUsage
The CLI will guide you through a series of questions to customize your project:
- Project name - Enter a directory name or use
.for the current directory - Language - Choose between TypeScript or JavaScript
- Module system - Select ESM (recommended) or CommonJS
- Source directory - Option to organize code in a
src/folder - ESLint - Optional code linting with ESLint v9
- Prettier - Optional code formatting with Prettier
- Git ignore - Automatic
.gitignorefile generation
Example
$ express-setup
? Project name: my-api
? Select language: TypeScript
? Select module system: ESM
? Use src directory? Yes
? Setup ESLint? Yes
? Setup Prettier? Yes
? Create .gitignore file? Yes
✓ Project setup complete!
Next steps:
cd my-api
npm run devCLI Options
Version
Display the current version:
express-setup --version
# or
express-setup -vHelp
Show help information:
express-setup --helpAvailable Scripts
After generating your project, the following npm scripts will be available:
Development
npm run devStarts the development server with hot-reload enabled. The server will automatically restart when you make changes to your code.
Build (TypeScript projects only)
npm run buildCompiles TypeScript to JavaScript in the dist/ directory.
Production
npm startStarts the production server using the compiled code from the dist/ directory.
Linting (if ESLint selected)
npm run lint # Check for linting errors
npm run lint:fix # Automatically fix linting errorsFormatting (if Prettier selected)
npm run formatFormats all code files according to Prettier configuration.
Project Configuration
TypeScript Configuration
TypeScript projects include a tsconfig.json with recommended settings:
- Strict mode enabled
- ES2022 target and module support
- Source maps for debugging
- Declaration files generation
ESLint Configuration
ESLint is configured with the latest v9 flat config format, including:
- Recommended ESLint rules
- TypeScript ESLint for TypeScript projects
- Prettier integration to avoid conflicts
Environment Variables
A .env file is automatically created with common configuration:
PORT=3000
NODE_ENV=developmentAdd your custom environment variables as needed.
Dependencies
Core Dependencies
- express (^4.21.1) - Web framework
- dotenv (^16.4.5) - Environment variable management
- cors (^2.8.5) - CORS middleware
TypeScript Development Dependencies
- typescript (^5.7.2)
- tsx (^4.19.2) - TypeScript execution for ESM
- ts-node-dev (^2.0.0) - TypeScript execution for CommonJS
- @types/express, @types/cors, @types/node
JavaScript Development Dependencies
- nodemon (^3.1.7) - Auto-restart on file changes
Optional Development Dependencies
- eslint (^9.15.0) - Code linting
- prettier (^3.3.3) - Code formatting
- typescript-eslint (^8.15.0) - TypeScript ESLint rules
- eslint-config-prettier (^9.1.0) - ESLint-Prettier integration
Requirements
- Node.js >= 18.0.0
- npm, yarn, or pnpm
Folder Structure
The generated project creates the following folder structure inside the src/ directory (if enabled):
config/- Application configuration filescontrollers/- Request handlers and business logicmiddleware/- Custom Express middlewaremodels/- Data models and schemasroutes/- API route definitionsservices/- Business logic layertypes/- TypeScript type definitions (TypeScript only)utils/- Utility functions and helpers
Use Cases
Quick Prototyping
Create a new Express API in seconds:
npx create-express-setupTypeScript Microservices
Generate a TypeScript-based microservice with full type safety:
npx create-express-setup
# Choose: TypeScript, ESM, src directory, ESLint, PrettierJavaScript REST API
Set up a lightweight JavaScript API:
npx create-express-setup
# Choose: JavaScript, CommonJS, no src directoryTeam Projects
Ensure consistent project structure across your team:
npx create-express-setup
# All team members use the same setupTroubleshooting
Module Resolution Errors
If you encounter module resolution errors with TypeScript ESM projects, ensure your imports include the .js extension:
import router from './routes/users.js'; // Correct
import router from './routes/users'; // May cause errorsHot Reload Not Working
For ESM TypeScript projects, the CLI uses tsx which provides better ESM support. If hot-reload isn't working:
- Check that your
package.jsonhas"type": "module" - Verify your
tsconfig.jsonhas"module": "ES2022" - Ensure all imports use the
.jsextension
npm install Fails
If dependency installation fails during setup, you can manually install:
cd your-project-name
npm installContributing
Contributions are welcome! Please feel free to submit issues or pull requests.
