Script Valley
Node.js: The Complete Runtime
Node.js Core Modules/Assessment

Practice & Assessment

Test your understanding of Node.js Core Modules

Multiple Choice Questions

5
1

What is the key difference between path.join and path.resolve?

2

Why should you use pipeline instead of pipe when working with Node.js streams?

3

Why must you use timingSafeEqual when comparing password hashes instead of ===?

4

What happens if you use fs.readFileSync inside an HTTP request handler in a production Node.js server?

5

Which method creates a cryptographically secure random token suitable for password reset links?

Coding Challenges

1
1

Stream-Based File Compressor CLI

Build a CLI script compress.js that accepts two arguments: an input file path and an output file path. Use Node.js streams (fs.createReadStream, zlib.createGzip, fs.createWriteStream, and stream/promises pipeline) to compress the input file with gzip and write it to the output path. Print the original file size and compressed file size after completion using fs.stat. Usage: node compress.js input.txt output.txt.gz. Output: 'Compressed: 1024 bytes to 312 bytes (69.5% reduction)'. Handle a missing input file with a clear error message. Estimated time: 25 minutes.

Medium

Mini Project

1

Static File Server with ETag Caching

Build an HTTP server using only Node.js built-in modules (http, fs, path, crypto) that serves static files from a ./public directory. Requirements: resolve requested URL to a file path inside ./public and prevent directory traversal attacks by checking the resolved path starts with the public directory absolute path; set the correct Content-Type header based on file extension (.html, .css, .js, .json, .png, .jpg); generate an ETag for each file using SHA-256 hash of its contents; return 304 Not Modified if the client sends a matching If-None-Match header; return 404 for missing files; stream file content using fs.createReadStream. Test with at least three different file types.

Hard
Practice & Assessment โ€” Node.js Core Modules โ€” Node.js: The Complete Runtime โ€” Script Valley โ€” Script Valley