← Back to Tutorials Chapter 14

Practice & Certification

Node.js Compiler

Node.js uses the V8 JavaScript engine, which features JIT (Just-In-Time) compilation. However, there are tools to compile Node.js applications into standalone executables.

# pkg - Package Node.js into executable
npm install -g pkg
pkg app.js --output myapp

# nexe - Create standalone executables
npm install -g nexe
nexe app.js --output myapp.exe

# Node SEA (Single Executable Applications) - experimental
# node --experimental-sea-config sea-config.json

Examples

REST API (Complete Example)

const express = require('express');
const app = express();
app.use(express.json());

let tasks = [];
let id = 1;

app.get('/tasks', (req, res) => res.json(tasks));

app.post('/tasks', (req, res) => {
  const { title } = req.body;
  if (!title) return res.status(400).json({ error: 'Title required' });
  const task = { id: id++, title, completed: false };
  tasks.push(task);
  res.status(201).json(task);
});

app.put('/tasks/:id', (req, res) => {
  const task = tasks.find(t => t.id === parseInt(req.params.id));
  if (!task) return res.status(404).json({ error: 'Task not found' });
  Object.assign(task, req.body);
  res.json(task);
});

app.delete('/tasks/:id', (req, res) => {
  tasks = tasks.filter(t => t.id !== parseInt(req.params.id));
  res.status(204).send();
});

app.listen(3000);

Exercises (All Chapters)

  1. Ch1: Create a script that prints your name, the date, and the OS platform.
  2. Ch2: Read 3 files in parallel, concatenate, and write to a new file.
  3. Ch3: Create an NPM project with chalk and print colored text.
  4. Ch4: Build a CLI tool that reads, compresses, hashes, and writes metadata.
  5. Ch5: Create a TypeScript file with a Task interface and compile it.
  6. Ch6: Build a task management REST API with Express.js.
  7. Ch7: Create a product catalog API with Mongoose and aggregations.
  8. Ch8: Build a real-time chat application with Socket.IO and rooms.
  9. Ch9: Write Jest tests for the task API with supertest.
  10. Ch10: Create a Dockerfile for the task API with multi-stage build.
  11. Ch11: Run the task API in cluster mode with PM2 and benchmark.
  12. Ch12: Propose a microservices architecture for an e-commerce app.
  13. Ch13: Build a weather station on Raspberry Pi with WebSockets.
  14. Ch14: Complete practice problems below.

Quiz

  1. What is the event loop in Node.js?
  2. What is the difference between CommonJS and ES Modules?
  3. How does Node.js handle multiple concurrent requests with a single thread?
  4. What are the phases of the event loop?
  5. When would you use worker_threads vs cluster?
  6. What is the purpose of the next() function in Express middleware?
  7. How do you handle unhandled promise rejections?
  8. What is the difference between require and import?
  9. How does the fs.promises API differ from fs callbacks?
  10. What is the purpose of package-lock.json?

Practice Problems

  1. Write a function that recursively lists all files in a directory tree.
  2. Create a command-line to-do app that persists tasks to a JSON file.
  3. Implement a rate limiter middleware for Express.
  4. Build a real-time stock price simulator using Socket.IO.
  5. Create a simple key-value store that persists to disk (similar to Redis).
  6. Implement a URL shortener service with Express and a database.
  7. Write a file watcher that logs changes and triggers a build script.

Study Plan

WeekTopicsGoal
1Ch1-2Understand Node.js architecture and async programming
2Ch3-4Master modules, NPM, and core modules
3Ch5-6Build web applications with Express
4Ch7-8Integrate databases and real-time communication
5Ch9-10Test, debug, and deploy applications
6Ch11-13Scale, optimize, and explore advanced topics
7Ch14-15Practice projects and review

Interview Preparation

Common Interview Questions

  1. Explain the Node.js event loop in detail.
  2. How do you handle errors in async functions?
  3. What is the difference between process.nextTick, setImmediate, and setTimeout?
  4. How does Node.js handle file system operations?
  5. Explain streams and buffers in Node.js.
  6. How would you scale a Node.js application?
  7. What are the security best practices for Node.js applications?
  8. How do you manage environment-specific configuration?
  9. Explain middleware in Express.js.
  10. How do you debug a Node.js application in production?

Bootcamp Projects

Certification Path

Consider the following certifications to validate your Node.js skills:

Final Exercise: Build a complete e-commerce REST API with the following features: user registration/login with JWT, product catalog with categories, shopping cart, order management, payment integration (Stripe mock), and admin dashboard endpoints. Write comprehensive tests and create a Docker Compose setup.