Skip to content

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.

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.

Every file in the Bulletin API uses what you learned here:

// src/config.ts — env validation
import 'dotenv/config'
export const config = { port: ..., jwtSecret: ..., dbPath: ... }
// src/db/index.ts — path + process
import { join } from 'path'
const db = new Database(join(process.cwd(), config.dbPath))
// src/db/schema.ts — fs + path
import { readFile } from 'fs/promises'
const schema = await readFile(join(process.cwd(), 'src/db/schema.sql'), 'utf8')
// src/index.ts — process.env
import 'dotenv/config'
app.listen(config.port, () => console.log(`API on port ${config.port}`))
TermWhat it means
CommonJSNode.js’s original module system: require/module.exports
ES ModulesStandard JavaScript modules: import/export
fs/promisesAsync 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.envDictionary of environment variables
dotenvPackage that loads .env into process.env for local dev
.env.exampleTemplate documenting required variables — safe to commit

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.