Node.js Assignments — Run. Stream. Scale.

Go from “hello runtime” to production-minded services. Each topic-wise set includes 20 Basic, 20 Intermediate, and 10 Advanced questions so learners can practice deliberately and level up fast.

Your five attached assignments span the core runtime, modules & events, files & streams, low-level HTTP/HTTPS + databases, and security/performance with workers and monitoring.

Why practice with these assignments?

  • Move beyond theory—inspect the process, schedule timers, handle events, and build servers with the built-in APIs.
  • Learn real-world files/streams (read, write, transform, backpressure) and wire HTTP endpoints that return HTML/CSS/JS/JSON.
  • Practice HTTPS, MySQL, MongoDB from Node’s side, plus routing patterns and error handling.
  • Build production habits: crypto, password hashing, JWT, worker_threads, pm2, caching, and logging/metrics.

How it works

  • Open any assignment and attempt the questions in order: Basic → Intermediate → Advanced.
  • Run locally with node (use nodemon for quick feedback), print outputs, and observe the event loop ordering.
  • Validate endpoints with a client (curl/Postman), inspect headers/status, and log timings.
  • Keep a short “what I learned” note per task; refactor for clarity and resilience.

What you’ll achieve

  • A solid mental model of the process, timers, and event loop (immediate vs timeout) with measurement tools.
  • Fluency with fs (async vs sync), streams (readable/writable/transform), buffers, and performance-aware file I/O.
  • Confidence building HTTP/HTTPS services and connecting MySQL/MongoDB end-to-end.
  • Practical security & performance skills: crypto, bcrypt, JWT, worker_threads, rate limiting, caching, monitoring.

Who should use this page?

Beginners learning Node.js, students preparing for interviews, and developers who want to turn core runtime knowledge into reliable, production-ready services.

Browse the Assignments

  • Core Runtime & CLI — __filename/__dirname, args with process.argv, env & versions, platform/arch, timers vs immediates, uptime, memory usage, and small event-loop demos.
  • Modules, Timers & Events — CommonJS modules, os/path/crypto, event emitters, small HTTP server with http, async vs sync file reads, console timing.
  • File System, Streams & HTTP — fs.readFile/writeFile, directories, watchers, buffers, transform/duplex streams, JSON APIs, static assets, logging & 404s.
  • HTTP/HTTPS & Databases — routes/params/query parsing, basic HTTPS, MySQL (mysql2) CRUD, MongoDB operations, connection pooling, secure/JSON APIs, and gateway ideas.
  • Security, Performance & Workers — crypto, bcrypt hashing & login flows, JWT auth, rate limiting, caching, worker_threads for CPU work, pm2 clustering, and full monitoring.

Tips for success

  • Prefer non-blocking APIs; measure with console.time and compare async vs sync paths.
  • Log method, URL, timestamps for every request while developing.
  • Keep secrets in environment variables (.env)—never hard-code credentials.
  • For CPU-heavy tasks, offload to worker_threads or use pm2 cluster; keep the event loop responsive.
  • Add rate-limits, input validation, and consistent error shapes for any public API.

Ready to build real confidence in Node JS? Pick a set below and start solving!

FAQs

Q1. Which Node.js version should I use for these assignments?
Use a recent LTS release. The tasks rely on APIs available across modern Node versions such as process, timers, fs, streams, and crypto, and reference current practices like worker_threads and pm2.

Q2. How do I run and verify my scripts?
Run scripts with node your-file.js. Confirm output, exit codes, and timing using console.time and console.timeEnd. For endpoints, test with curl or Postman and check headers and status codes.

Q3. What’s the difference between setTimeout, setImmediate, and event loop turns?
You’ll stage tasks with all three to observe execution order and micro-timing differences. This helps in understanding scheduling, and you’ll compare outputs in the core runtime assignments.

Q4. When should I use streams instead of reading a whole file?
Use streams for large files or continuous data. They reduce memory usage and enable transforms and pipes. You’ll implement readable, writable, and transform streams while measuring chunk sizes.

Q5. How do I decide between sync and async fs operations?
Prefer async methods in servers to avoid blocking. Compare execution time and responsiveness using the provided exercises. Use sync methods only in startup scripts or small tooling.

Q6. Do these assignments cover HTTPS and databases?
Yes. You’ll create HTTPS servers with self-signed certificates and connect to MySQL and MongoDB for CRUD operations, pooling, and combined results endpoints.

Q7. Where do security topics like hashing and JWTs fit?
They appear in the security and performance assignments. You’ll hash and compare passwords, implement JWT authentication, rate-limit requests, and log or monitor the system.

Q8. How do I handle CPU-bound tasks without freezing my API?
Offload them to worker_threads or scale with pm2 clusters. You’ll also simulate event-loop delays and measure performance improvements.

Q9. What’s the recommended way to manage configuration?
Keep configuration values in a .env file and load them with process.env. Never commit secrets to version control. You’ll practice safe config handling and usage across scripts.

Q10. How much time should I allocate per assignment?
Plan 10–60 minutes per difficulty band. More advanced tasks like streams, HTTPS with databases, and worker threads may take longer—focus on correctness and observability.