Module 41: Node.js Fundamentals

Lesson 3 of 5 · 15–25 minutes

Modules in a backend project

🏠The everyday picture

A hospital with departments: reception, records, pharmacy, wards. Each has a clear job and talks to the others in agreed ways.

📘What it really is

enquiries-api/
  src/
    server.ts        starts the server
    app.ts           sets up the app and routes
    routes/          addresses and methods
    services/        business rules
    data/            storage
    config.ts        settings
  tests/
  package.json
  tsconfig.json
  .env.example
"scripts": {
  "dev": "node --watch src/server.ts",
  "check": "tsc --noEmit",
  "test": "node --test \"tests/**/*.test.ts\""
}

🖱️Try it

Create the folder structure above with a tsconfig.json (strict, with the settings from Modules 27 and 29). In server.ts, print "Server starting". Run npm run dev, change the message, save, and watch it restart.

✅Quick check

What does node --watch do?

Show the answer

Restarts the program automatically whenever you save a file.

Running .ts files with Node.js works. Why still run tsc --noEmit?

Show the answer

Node removes types without checking them; tsc actually checks.

← Previousnpm and package.json in depth
ProLearners Assist