MyInternships.in

Express.js & REST APIs

Node.js Express Project Structure

A maintainable Express project separates routing, business logic and data access. Routes describe URLs, controllers coordinate, services hold the logic, and models talk to the database.


What is Express Project Structure in Node.js?

A maintainable Express project separates routing, business logic and data access. Routes describe URLs, controllers coordinate, services hold the logic, and models talk to the database.

Express Project Structure example

A layered structure
Output
src/
├── index.js            # bootstrap: config, db, app.listen
├── app.js              # express app, middleware, route mounting
├── config/             # env parsing, database connection
├── routes/             # jobs.routes.js — URLs only
├── controllers/        # jobs.controller.js — req/res handling
├── services/           # jobs.service.js — business logic, no req/res
├── models/             # jobs.model.js — schema and queries
├── middleware/         # auth, validate, errorHandler
└── utils/              # logger, helpers

Key points to remember

  • Services must not touch req or res — that keeps them testable and reusable.
  • Separating app.js from index.js lets tests import the app without starting a server.
  • Keep each layer thin; a controller that is fifty lines is doing service work.

Common mistakes with Express Project Structure

  • Database queries written directly inside route handlers.
  • Business logic in controllers, which makes it impossible to reuse from a job or CLI.

Node.js Express Project Structure— Interview Questions & FAQs

How should I structure a Node.js Express project?+

Layer it: routes define URLs, controllers handle request and response, services hold business logic, models handle data. Split app creation from server startup so tests can import the app directly.

Related Node.js Topics

Keep learning with these closely related lessons.

Ready to use your Node.js skills?

Find verified Node.js internships and fresher developer jobs across India.

Browse Node.js Internships