Skip to Content
GuidesFolder Structure

Folder Structure

NeatNode provides different folder structures for JavaScript and TypeScript templates, each optimized for clarity and scalability.


JavaScript Templates — Typical Structure

Used by Basic (JS), REST API (JS), and Socket.IO (JS) templates.

<project-root>/ ├── package.json ├── server.js └── src/ ├── app.js ├── config/ ├── controllers/ ├── models/ ├── routes/ ├── services/ ├── middleware/ └── utils/

This structure follows a layer-based architecture, separating concerns clearly.


JavaScript Template Folders /src

controllers/

Request handlers mapped to routes.

routes/

Defines API endpoints.

services/

Business logic and database interactions.

models/

Mongoose schemas or DB models.

middleware/

Auth, validation, and error handling.

utils/

Shared helpers like ApiError, ApiResponse, CatchAsync.


TypeScript Templates — Module-Based Structure

Used by Basic (TS) and all upcoming TypeScript templates.

<project-root>/ ├── package.json ├── tsconfig.json ├── src/ ├── app.ts ├── server.ts ├── config/ ├── modules/ └── user/ ├── user.controller.ts ├── user.service.ts ├── user.route.ts ├── user.model.ts └── user.types.ts ├── middleware/ └── utils/ └── dist/

Each module owns its logic, making large codebases easier to scale and maintain.


Root Files

FilePurpose
package.jsonDependencies and scripts
server.js / server.tsApplication entry point
app.js / app.tsExpress configuration
tsconfig.jsonTypeScript compiler configuration
.env / .env.exampleEnvironment variables

TypeScript Template Folders /src

modules/

Feature-based modules. Each module contains its own controller, service, routes, and model.

Example:

modules/user/ ├── user.controller.ts ├── user.service.ts ├── user.route.ts ├── user.model.ts └── user.types.ts

config/

Database, logger, environment setup.

middleware/

Typed middleware (auth, validation, errors).

utils/

Typed helpers, error classes, response wrappers.


Template Variations

TemplateStructure TypeNotes
Basic (JS)Layer-basedMinimal Express setup
REST API (JS)Layer-basedAuth + validation
Socket.IO (JS)Layer-basedAdds socket config
Basic (TS)Module-basedStrict typing
REST API (TS)Module-based(Coming soon)
Socket.IO (TS)Module-based(Coming soon)

Extending the Structure

You can safely add new folders in both JS and TS templates:

src/ jobs/ # Background jobs validators/ # Custom schema validation scripts/ # Seeding or CLI scripts

Request Flow Comparison

JavaScript (Layer-Based)

Route → Controller → Service → Model → Response

TypeScript (Module-Based)

Route → Controller → Service → Model → Response (all inside one module)

✅ Summary

  • JS templates → layer-based structure
  • TS templates → module-based structure
  • Same concepts, different organization
  • Easy to scale, easy to understand

[!TIP] Once you understand one template, switching between JS and TS is straightforward.