A fast, scannable reference covering the syntax and patterns from across this entire Node.js course, useful while actively building rather than re-reading full lessons.
How to Use This Cheat Sheet
Each table below groups related syntax by topic, core modules, async patterns, Express, databases, and security essentials, matching the structure of this course. Use it as a quick lookup while coding, and jump back to the full lesson whenever you need the deeper explanation behind a pattern.
import fs from 'node:fs/promises';
import path from 'node:path';
import express from 'express';
const app = express();
app.use(express.json());
app.get('/health', (req, res) => res.json({ status: 'ok' }));
app.listen(process.env.PORT || 3000);
A minimal but representative snippet touching several of the topics covered in the tables below.
Running and Managing a Project
node app.js # run a script
node --watch app.js # auto-restart on changes
npm install express # add a dependency
npm run dev # run a package.json script
node --test # run tests with the built-in runner
node --watch restarts your script automatically on file changes, no extra package required.
npm run <script> executes anything defined under package.json's scripts field.
node --test runs the built-in test runner across *.test.js files.
Core Modules Quick Reference
The built-in modules covered throughout this course.
Module
Common Use
Example
node:fs
Read/write files
await fs.readFile(path, 'utf8')
node:path
Build cross-platform paths
path.join(a, b, 'c.txt')
node:http
Raw HTTP server
http.createServer(handler)
node:crypto
Hashing, random values
crypto.randomUUID()
node:os
System information
os.cpus().length
node:events
Custom event emitters
class X extends EventEmitter
node:worker_threads
CPU-bound parallelism
new Worker('./worker.js')
node:child_process
Run external commands
spawn(cmd, args)
Async Patterns Quick Reference
Pattern
Example
Callback
fs.readFile(path, (err, data) => {})
Promise
fs.promises.readFile(path).then((data) => {})
Async/await
const data = await fs.promises.readFile(path);
Parallel
await Promise.all([a(), b(), c()]);
Settle all
await Promise.allSettled([a(), b()]);
Express Quick Reference
Task
Code
Create app
const app = express();
Route
app.get('/path', handler)
Middleware
app.use(middleware)
Route param
req.params.id
Query string
req.query.page
JSON response
res.json(data)
Status code
res.status(201).json(data)
Error middleware
app.use((err, req, res, next) => {})
Database Quick Reference
Task
Example
PostgreSQL query
pool.query('SELECT * FROM t WHERE id = $1', [id])
MySQL query
pool.query('SELECT * FROM t WHERE id = ?', [id])
MongoDB find
collection.find({ field: value }).toArray()
Mongoose create
await Model.create(data)
Mongoose find by id
await Model.findById(id)
Security Quick Reference
Task
Code
Security headers
app.use(helmet())
CORS
app.use(cors({ origin: allowedOrigins }))
Rate limiting
app.use(rateLimit({ windowMs, max }))
Hash a password
await bcrypt.hash(password, 12)
Verify a password
await bcrypt.compare(password, hash)
Sign a JWT
jwt.sign(payload, secret, { expiresIn: '1h' })
Verify a JWT
jwt.verify(token, secret)
Common Mistakes
Using this cheat sheet as a substitute for understanding why each pattern works the way it does.
Copying a snippet without checking it matches your project's module system (CommonJS vs ESM).
Skipping the security quick reference when shipping a new API endpoint.
Not revisiting the full lesson when a quick-reference snippet doesn't behave as expected.
Key Takeaways
This cheat sheet consolidates syntax from every major topic covered in this Node.js course.
Core modules, async patterns, Express, databases, and security each have a dedicated quick-reference table.
Use it for fast lookups while coding, and the full lessons for deeper understanding.
Bookmark this page as your go-to reference while building real Node.js projects.
Pro Tip
Keep this cheat sheet open in a browser tab while working through your first few real Node.js projects. Referencing exact syntax quickly, rather than context-switching to search engines repeatedly, keeps you in flow while you're still building muscle memory for these patterns.
You now have a fast reference for this entire course. Next, explore curated Node.js resources for going even deeper.