Node.js Project Structure

๐ŸŸข Node.js LTS ๐Ÿ“— Chapter 5 of 49 ๐Ÿ“‚ Phase 2: Setup & First Program ๐Ÿ—“๏ธ 2026 Edition
๐Ÿ“Œ Covered in this chapter: package.json ยท node_modules ยท src Folder Layout ยท routes/controllers/services/models ยท .gitignore

Learn the standard folder layout used in real Node.js backend projects โ€” package.json, src, routes, controllers, services, models and more.

1Node.js Project Structure โ€” What You'll Learn

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
2Working Example
๐Ÿ’ป Example: Node.js Project Structure
node-app/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app.js
โ”‚   โ”œโ”€โ”€ server.js
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ middleware/
โ”‚   โ””โ”€โ”€ config/
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ .env
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ package-lock.json
3Best Practices & Common Pitfalls
๐Ÿ’ก Key things to remember:
  • 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.
โ“ Frequently Asked Questions (FAQ)

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.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on Node.js LTS ยท Last updated August 2026