ts-node-init
v1.1.3
Published
Bootstrap a fully-configured Node.js + TypeScript project with ESLint, Prettier, Jest, and ready-to-use npm scripts.
Maintainers
Readme
ts-node-init
A powerful CLI tool to bootstrap modern Node.js + TypeScript projects with Express.js and MongoDB support in seconds. Stop wasting time on configuration and start building features immediately.
✨ Features
- 🚀 Express.js + MongoDB - Full-stack REST API setup with modular architecture
- 📦 TypeScript - Preconfigured with strict mode and best practices
- 🎨 Code Quality - ESLint + Prettier integration for consistent code
- 🧪 Testing - Jest + ts-jest ready for TypeScript testing
- 📁 Clean Architecture - Organized modular folder structure (controller, service, routes, model)
- 🔧 Production Ready - Pino logger, error handling, and environment variables
- 🗄️ Database - Mongoose models with TypeScript types
- ⚡ Dev Experience - Hot reload with ts-node-dev
- 🛡️ Safe Operation - Prevents overwriting existing projects
- 🎯 Interactive Setup - Choose only the features you need
- 💨 Quick Mode - Skip prompts with
-yflag
📦 Installation
Install globally via npm:
npm install -g ts-node-initOr use directly with npx (no installation required):
npx ts-node-init my-project🚀 Usage
Interactive Mode (Recommended)
ts-node-init my-projectYou'll be asked to configure:
- ✅ Express.js setup
- ✅ MongoDB integration
- ✅ Prettier formatting
- ✅ ESLint linting
- ✅ .gitignore file
Quick Mode
Skip all prompts and create a full-featured project:
ts-node-init my-project -y
# or
ts-node-init my-project --yesThis creates a project with all features enabled (Express + MongoDB + Prettier + ESLint).
Initialize in Current Directory
ts-node-init .Sets up the project in your current folder. Aborts if package.json exists to prevent overwriting.
📁 Project Structure
Full Stack Setup (Express + MongoDB)
my-project/
├── config/
│ └── default.ts # Environment configuration
├── src/
│ ├── index.ts # Application entry point
│ ├── shared/
│ │ └── utils/
│ │ ├── server.ts # Express app setup
│ │ ├── connect.ts # MongoDB connection
│ │ └── logger.ts # Pino logger
│ └── modules/
│ └── user/ # Example user module
│ ├── controller/
│ │ └── user.controller.ts
│ ├── service/
│ │ └── user.service.ts
│ ├── routes/
│ │ └── user.routes.ts
│ └── model/
│ └── user.model.ts
├── .env # Environment variables
├── .env.example # Environment template
├── .gitignore
├── .prettierrc # Prettier config (optional)
├── .eslintrc.json # ESLint config (optional)
├── package.json
├── tsconfig.json
└── jest.config.jsonBasic Setup (Node.js only)
my-project/
├── src/
│ └── app.ts # Sample TypeScript file
├── package.json
├── tsconfig.json
└── jest.config.json🛠️ Available Scripts
Once your project is created:
npm run dev # Start development with hot reload
npm run build # Compile TypeScript to JavaScript
npm start # Run production build
npm test # Run tests in watch mode
npm run test:coverage # Run tests with coverage
npm run format # Format code with Prettier (if enabled)
npm run format:check # Check code formatting (if enabled)
npm run lint # Lint code with ESLint (if enabled)
npm run lint:fix # Auto-fix linting issues (if enabled)🎯 Quick Start Examples
Create a REST API
# Create project with Express + MongoDB
npx ts-node-init my-api -y
# Navigate and configure
cd my-api
# Update MONGO_URI in .env file
# Then start development
npm run devServer runs at http://localhost:3000 with:
- Health check:
GET /health - User routes:
GET /api/user
Create a Simple Node.js App
# Create project (choose 'n' for Express)
npx ts-node-init my-app
# Start coding
cd my-app
npm run dev⚙️ Configuration Details
TypeScript (tsconfig.json)
- Target: ES2020
- Module: CommonJS
- Module Resolution: Node
- Strict mode: Enabled
- Source folder:
src/ - Output folder:
build/ - JSON support: Enabled
Environment Variables (.env)
PORT=3000
NODE_ENV=development
MONGO_URI=mongodb://localhost:27017/your-databaseModular Architecture
Each module follows a clean separation of concerns:
- Controller - Handles HTTP requests/responses
- Service - Contains business logic
- Routes - Defines API endpoints
- Model - Mongoose schema and types
This structure makes it easy to:
- Add new features as modules
- Test components independently
- Scale your application
- Maintain clean code
📚 What Gets Installed
Production Dependencies
express- Web framework (if selected)cors- CORS middleware (if Express selected)mongoose- MongoDB ODM (if MongoDB selected)dotenv- Environment variablespino- Fast logger (if MongoDB selected)pino-pretty- Pretty logs (if MongoDB selected)dayjs- Date manipulation (if MongoDB selected)
Development Dependencies
typescript- TypeScript compilerts-node-dev- Development server with auto-reload@types/node- Node.js type definitions@types/express- Express type definitions (if selected)@types/cors- CORS type definitions (if selected)jest- Testing frameworkts-jest- TypeScript support for Jest@types/jest- Jest type definitionsprettier- Code formatter (if selected)eslint- Code linter (if selected)@typescript-eslint/parser- TypeScript parser (if selected)@typescript-eslint/eslint-plugin- TypeScript rules (if selected)
💡 Use Cases
Perfect for:
- ✅ REST API development
- ✅ Microservices architecture
- ✅ Backend applications with MongoDB
- ✅ Express.js projects
- ✅ Full-stack applications
- ✅ CLI tools and scripts
- ✅ TypeScript learning projects
- ✅ Teams wanting consistent structure
- ✅ Rapid prototyping
- ✅ Hackathons and MVPs
🔧 Advanced Usage
Adding New Modules
Follow the existing pattern to add new modules:
mkdir -p src/modules/posts/{controller,service,routes,model}Then create your controller, service, routes, and model files following the user module pattern.
Custom Configuration
The generated config/default.ts can be extended with your own environment variables and settings.
Database Connection
MongoDB connection happens automatically on server start. Update MONGO_URI in .env to point to your database.
📋 Requirements
- Node.js v14 or higher (v16+ recommended)
- npm v6 or higher (v8+ recommended)
- MongoDB (optional, only if using MongoDB features)
🤝 Contributing
Issues and pull requests are welcome! Visit the GitHub repository to contribute.
Development
# Clone the repository
git clone https://github.com/abdulwarith001/ts-node-init.git
# Install dependencies
npm install
# Test locally
npm link
ts-node-init test-project📄 License
MIT
👨💻 Author
Enigmare
- GitHub: @abdulwarith001
- X (Twitter): @enigmare_
🙏 Acknowledgments
Built with ❤️ for developers who value their time.
Stop configuring. Start building. 🚀
Save hours of setup time and jump straight into development with production-ready project structure.
