Module Recap
Module 02 covered the runtime foundations every Node.js project depends on: the two module systems, the file system, path utilities, the process object, and environment variables. These aren’t flashy features — but every line of the Bulletin API uses them.
What you learned
Section titled “What you learned”CommonJS and ES Modules are two module systems. CommonJS (require/module.exports) is the original Node.js system — still common in older code and some npm packages. ES Modules (import/export) are the standard — what TypeScript with "module": "NodeNext" compiles to. The Bulletin API uses ESM.
The fs module reads and writes files. Use fs/promises for async operations in request handlers. Synchronous fs is only acceptable at startup, before the server handles requests. fs is used for config loading and dev utilities — the database handles application data.
The path module builds portable paths. path.join and path.resolve handle path separators cross-platform. Always use them instead of string concatenation. process.cwd() gives you the project root as an absolute path.
process is the runtime’s window into the operating system. process.env holds environment variables. process.argv holds command-line arguments. process.exit() terminates the process. None of these need importing — process is always available.
dotenv bridges local development and production. .env files store secrets locally; hosting platforms inject them as environment variables in production. Never commit .env. Always commit .env.example. Validate required variables at startup.
How this connects to Bulletin
Section titled “How this connects to Bulletin”Every file in the Bulletin API uses what you learned here:
// src/config.ts — env validationimport 'dotenv/config'export const config = { port: ..., jwtSecret: ..., dbPath: ... }
// src/db/index.ts — path + processimport { join } from 'path'const db = new Database(join(process.cwd(), config.dbPath))
// src/db/schema.ts — fs + pathimport { readFile } from 'fs/promises'const schema = await readFile(join(process.cwd(), 'src/db/schema.sql'), 'utf8')
// src/index.ts — process.envimport 'dotenv/config'app.listen(config.port, () => console.log(`API on port ${config.port}`))Key terms
Section titled “Key terms”| Term | What it means |
|---|---|
| CommonJS | Node.js’s original module system: require/module.exports |
| ES Modules | Standard JavaScript modules: import/export |
fs/promises | Async file system API — use in request handlers |
path.join(...) | Cross-platform path builder |
process.cwd() | Current working directory — the project root when running npm run dev |
process.env | Dictionary of environment variables |
| dotenv | Package that loads .env into process.env for local dev |
.env.example | Template documenting required variables — safe to commit |
What is next
Section titled “What is next”Module 03 — Express and HTTP →
Module 03 introduces Express — the framework the Bulletin API is built on. You’ll create an HTTP server, define routes for different URL paths and HTTP methods, read route parameters and query strings, and understand the full request/response cycle. By the end of Module 03 you’ll have a working API that responds to HTTP requests.