Node.js Project Structure
Learn the standard folder layout used in real Node.js backend projects โ package.json, src, routes, controllers, services, models and more.
Learn the standard folder layout used in real Node.js backend projects โ package.json, src, routes, controllers, services, models and more.
Here's everything this chapter covers, in the order you'll learn it:
- package.json โ your project's manifest
- package-lock.json โ exact dependency versions
- node_modules โ installed packages (never edit directly)
- src folder for your source code
- routes folder for endpoint definitions
- controllers folder for request handlers
- services folder for business logic
- models folder for data structures
- middleware folder for request pipeline functions
- config folder for settings
- tests folder for automated tests
- .gitignore to exclude node_modules and secrets from Git
node-app/
โโโ src/
โ โโโ app.js
โ โโโ server.js
โ โโโ routes/
โ โโโ controllers/
โ โโโ services/
โ โโโ models/
โ โโโ middleware/
โ โโโ config/
โโโ tests/
โโโ .env
โโโ .gitignore
โโโ package.json
โโโ package-lock.json
- Never commit node_modules or .env to Git โ always add them to .gitignore.
- This layered structure (routes โ controllers โ services โ models) keeps your codebase testable and easy to navigate as it grows.
Q What's the most important thing to understand about node.js project structure?
Focus on: package.json ยท node_modules ยท src Folder Layout ยท routes/controllers/services/models ยท .gitignore. These are the core building blocks this chapter's examples are built around, and they show up repeatedly in later chapters of this course.
Q Do I need external npm packages for node.js project structure?
Only where explicitly shown in the code examples above (like Express, Zod, or Socket.IO) โ otherwise, this chapter relies entirely on Node.js's own built-in capabilities.