Node.js Exercises
Fill in the blanks to check your knowledge. Each exercise belongs to a lesson.
Node.js Introduction
Exercise
Print to the terminal.
.log("Hi");Get Started
Exercise
Run app.js.
app.jsModules
Exercise
Load a module with CommonJS.
const fs = ("fs");
npm and package.json
Exercise
Add a package.
npm express
Globals and process
Exercise
Read an environment variable.
process..PORT
The console Object
Exercise
Write to the error stream.
console.("oops")
Modern JavaScript in Node
Exercise
Use the nullish operator.
x "default"
The path Module
Exercise
Get the file extension.
path.("a.js")
The os Module
Exercise
Get the temp folder.
os.()
URL and URLSearchParams
Exercise
Read a query value.
u.searchParams.("x")
The util Module
Exercise
Convert a callback function.
util.(fn)
Buffers
Exercise
Create a buffer from text.
Buffer.("hi")
Timers and the Event Loop Order
Exercise
Run before promises.
process.(fn)
Environment Variables and Arguments
Exercise
Read a variable.
process..PORT
Errors and Error Codes
Exercise
Catch an error.
try { risky() } (e) {}
ES Modules and Dynamic Import
Exercise
Load a module on demand.
("node:os")npm Scripts and Versions
Exercise
Run a script.
npm dev
Running Node.js
Exercise
Run a file.
node Variables and Types
Exercise
Constant.
x = 1;Functions and Arrows
Exercise
Arrow.
const f = (x) x * 2;
Objects and JSON
Exercise
Object to text.
JSON.(obj)
CommonJS Modules
Exercise
Load a module.
const fs = ("fs");
ES Modules
Exercise
Dynamic import.
("node:os")Command Line Arguments
Exercise
User arguments.
process.argv.(2)
The process Object
Exercise
Current folder.
process.()
Environment Variables
Exercise
Default port.
const port = process.env.PORT ?? ;
console Methods
Exercise
Show rows as a table.
console.(rows)
Template Strings
Exercise
Embed.
`Hi name}`
Destructuring and Spread
Exercise
Spread.
[arr, 4]
Array Methods
Exercise
Filter items.
n.((x) => x > 2)
Classes
Exercise
Private field.
n = 0;Callbacks and Error First
Exercise
Error first.
(, data) => {}
Promises
Exercise
Handle errors.
p.(handler)
async and await
Exercise
Pause for a promise.
wait(10)The Event Loop
Exercise
Runs before promises.
process.(fn)
Timers
Exercise
Stop an interval.
(id)File System
Exercise
Read a file as text.
await fs.readFile(file, "")
Events
Exercise
Fire an event.
bus.("order", 1)
Callbacks, Promises and async/await
Exercise
Wait for a promise.
const v = wait(10);
Promises with fs/promises
Exercise
Add text to a file.
await fs.(f, "x")
Folders and File Information
Exercise
List a folder.
fs.Sync(dir)
Streams and pipeline
Exercise
Connect streams safely.
(a, b, c)Reading Lines with readline
Exercise
Loop over lines.
for await (const l of )
Running Other Programs
Exercise
Run a command.
("echo hi")Hashing and Crypto
Exercise
Create a hash object.
crypto.("sha256")
Compression with zlib
Exercise
Compress with gzip.
zlib.Sync(data)
EventEmitter In Depth
Exercise
Listen one time.
e.("x", fn)
Timers Promises and AbortController
Exercise
Cancel an operation.
ac.()
path Module
Exercise
Join parts.
path.("a", "b")
Reading and Writing Files
Exercise
Read as text.
fs.readFileSync(f, "")
fs.promises
Exercise
Async read.
await fs.(f, "utf8")
Directories
Exercise
List a folder.
fs.(dir)
Checking Files
Exercise
Error code for missing.
e.code === ""
EventEmitter
Exercise
Fire an event.
e.("hi")
Error Events
Exercise
Listen for errors.
e.on("", fn)
Buffers
Exercise
Bytes.
Buffer.("hi")
Streams
Exercise
Chunk event.
r.on("", fn)
pipeline and Transform
Exercise
Connect streams.
(a, b, cb)readline
Exercise
Line event.
rl.on("", fn)
os Module
Exercise
Temp folder.
os.()
URL and URLSearchParams
Exercise
Read a query value.
u.searchParams.("q")
util Module
Exercise
Callback to promise.
util.(fn)
crypto
Exercise
Hash text.
crypto.createHash("")
child_process
Exercise
Run a command.
("echo hi")zlib
Exercise
Compress.
zlib.Sync(data)
Worker Threads
Exercise
CPU heavy work.
new (file)
HTTP Server
Exercise
Start listening.
server.(3000)
JSON and Streams
Exercise
Turn an object into text.
JSON.(obj)
HTTP Server and fetch Together
Exercise
Listen on a random port.
server.listen()
Routing by Hand
Exercise
Not found status.
res.statusCode = A JSON REST Handler
Exercise
Status for created.
res.statusCode = Headers and Cookies
Exercise
Set a response header.
res.("X-A", "1")
Configuration and dotenv
Exercise
Load a .env file.
node =.env app.js
Rendering HTML
Exercise
Name the attack.
injectionWebSockets and Server Sent Events
Exercise
Send a message.
socket.("hi")
A Basic HTTP Server
Exercise
Start listening.
server.(3000)
Routing by Hand
Exercise
Not found status.
res.statusCode = fetch in Node
Exercise
Parse JSON.
await res.()
Reading a Request Body
Exercise
Event with chunks.
req.on("", fn)
HTTP Status Codes
Exercise
Not found.
Not FoundHeaders and CORS
Exercise
CORS header.
Access-Control-Allow-Cookies
Exercise
Hide from scripts.
Set-Cookie: sid=1; Serving Static Files
Exercise
Safe file name.
path.(req.url)
Query Strings
Exercise
Read a param.
searchParams.("name")
A JSON API
Exercise
JSON type.
"application/"
Express in One Look
Exercise
Install it.
npm express
Middleware Idea
Exercise
Continue the chain.
()Configuration with dotenv
Exercise
Env file flag.
node ---file=.env
npm Commands
Exercise
Run a script.
npm start
Semantic Versioning
Exercise
Breaking changes bump.
The number
The Built in Test Runner
Exercise
Assert equal.
assert.Equal(a, b)
assert Module
Exercise
Deep compare.
assert.StrictEqual(a, b)
Error Types and Custom Errors
Exercise
Custom error.
class E Error
Uncaught Errors
Exercise
Rejection event.
process.on("Rejection", fn)
Modern Globals
Exercise
Deep copy.
(obj)Cancelling with AbortController
Exercise
Cancel.
ac.()
Practice: Group and Count
Exercise
Split words.
text.(" ")
Practice: A Tiny CLI
Exercise
Spread arguments.
ops[cmd](n)
Practice: Log File Summary
Exercise
Split lines.
.split("")
Express and REST APIs
Premium exercise. See plans
Testing with node:test
Premium exercise. See plans
Worker Threads and Performance
Premium exercise. See plans
Security and Deployment
Premium exercise. See plans
Transform Streams
Premium exercise. See plans
AsyncLocalStorage
Premium exercise. See plans
Measuring Performance
Premium exercise. See plans
Assertions with node:assert
Premium exercise. See plans
Built in SQLite
Premium exercise. See plans
Modern Globals
Premium exercise. See plans
Cluster and Process Managers
Premium exercise. See plans
Express Middleware
Premium exercise. See plans
TypeScript with Node
Premium exercise. See plans
Project Structure
Premium exercise. See plans
Handling Async Errors
Premium exercise. See plans
Graceful Shutdown
Premium exercise. See plans
Logging
Premium exercise. See plans
Security Checklist
Premium exercise. See plans
Docker and Deployment
Premium exercise. See plans
Node.js Best Practices
Premium exercise. See plans