Node.js + Express Backend Folder Structure & Starter Template
A ready-to-use starter template for building scalable backend applications using Node.js, Express, and MongoDB. Designed with a clean folder structure and pre-integrated packages to kickstart your development — ideal for real-world projects with authentication, error handling, and more out of the box.
🚀 Quick Start
Run this to create a new Express.js project:
npx node-express-kit your-app-name
Folder Structure
config/ → Environment and database config (e.g., db.js, cloudinary.js)
controllers/ → Request handlers and business logic
middleware/ → Custom middleware (auth, error handling, logging)
models/ → Mongoose schemas for MongoDB collections
routes/ → Route definitions
services/ → Third-party service handlers (email, cloud uploads, etc.)
utils/ → Helper functions (token generator, OTP handler, etc.)
validators/ → Input validation logic (e.g., using Joi or express-validator)
uploads/ → File upload directory (optional)
app.js → Initializes Express, middleware, and routes
server.js → Entry point to launch the Node server
Integrated Packages
This starter kit comes pre-configured with essential npm packages for rapid backend development:
- express – Web server framework
- cookie-parser – To handle HTTP cookies
- bcryptjs – For secure password hashing
- mongoose – ODM to interact with MongoDB
- jsonwebtoken (JWT) – For token-based authentication
- cors – Enable CORS for cross-origin requests
- dotenv – Manage environment variables
- nodemon – Auto-restart server in development
Features
- Default error handling (includes MongoDB errors & async error catching)
- Default success response handler
- User registration & login
- JWT-based route protection with role-based authorization
- Password hashing with bcryptjs
- Cookie-based auth handling
- CORS setup included
- MongoDB integration using Mongoose
- Scalable MVC architecture for long-term projects
- Environment-based configuration with dotenv
- Basic APIs: register-user, login, logout, profile, view-users (admin only)
Thank you for using this npm package. If you have suggestions for additional features or improvements, feel free to share!