Node.js – 100+ Lab Exercises (Basic, Intermediate, Advanced)
🔰 Basic Level (30+ Exercises)
Goal: Understand core Node.js features including modules, file systems, and event-driven architecture.
Introduction to Node.js
Print “Hello from Node.js”.
Display command-line arguments using
process.argv.Create a simple script to add two numbers from CLI.
Setup and run a basic
package.json.Use npm to install and run a package.
Core Modules
Use the
fsmodule to read/write files.Create and delete files dynamically.
Use
pathto join and resolve file paths.Log system information using the
osmodule.Create a basic timer using the
timersmodule.
Modules & Exports
Create a reusable math utility module.
Export and import functions between files.
Demonstrate module caching.
Structure code with CommonJS modules.
Events & EventEmitter
Create and trigger custom events.
Build a file watcher using
EventEmitter.Use event listeners for different events.
HTTP Server Basics
Create a basic HTTP server with
http.Serve HTML content via
res.end().Send dynamic responses based on URL path.
Set appropriate headers and status codes.
🚀 Intermediate Level (40+ Exercises)
Goal: Implement REST APIs, use Express.js, and connect with databases.
Express.js Fundamentals
Setup an Express.js server.
Define multiple routes (GET, POST, PUT, DELETE).
Use route parameters and query strings.
Send JSON responses.
Handle form data with
body-parser.
Routing & Middleware
Create global and route-specific middleware.
Implement error-handling middleware.
Create an authentication middleware.
Use CORS middleware for cross-origin requests.
Organize routers using
express.Router().
File & Directory Operations
Upload files using
multer.Create an image gallery with uploaded files.
Handle JSON data and save it to local files.
Generate logs using a custom logger module.
Working with Databases
Connect Node.js to MongoDB using Mongoose.
Define and use MongoDB schemas.
Perform CRUD operations (create, read, update, delete).
Use PostgreSQL with
pgfor querying.Create REST API with database persistence.
Async Programming
Use callbacks to manage I/O tasks.
Rewrite logic using Promises.
Convert Promises to async/await.
Handle nested async operations with try/catch.
🧠 Advanced Level (40+ Exercises)
Goal: Build production-ready services with security, real-time updates, and scalability.
Advanced Express & REST APIs
Build a complete CRUD API with route validation.
Use
Joifor input validation.Integrate Swagger/OpenAPI documentation.
Use
dotenvto manage environment variables.Implement pagination and filtering.
Authentication & Security
Create JWT-based user authentication.
Hash passwords with
bcrypt.Secure routes using authentication middleware.
Set up role-based access control.
Sanitize input to prevent injection attacks.
WebSocket & Real-Time Apps
Create a real-time chat app using
socket.io.Emit and listen for socket events.
Broadcast messages to all clients.
Maintain a list of active users in real-time.
Integrate WebSocket with Express server.
Package Ecosystem & Tools
Use
nodemonfor auto-restarts.Use
morganfor HTTP request logging.Create a CLI tool using
yargs.Bundle code using Webpack or esbuild.
RESTful & MVC Architecture
Organize code using Model-View-Controller pattern.
Use services and repositories.
Separate route, controller, and business logic.
Implement advanced error handling using a centralized utility.
Deployment & DevOps
Prepare app for production with
pm2.Create a
Dockerfilefor containerization.Connect app to a remote MongoDB Atlas cluster.
Deploy on Heroku, Vercel, or Render.
Monitor performance with New Relic or LogRocket.
Testing & Quality Assurance
Write unit tests using Jest.
Create integration tests using Supertest.
Mock database operations for isolation.
Measure test coverage.
Implement CI/CD pipelines using GitHub Actions.
Capstone Projects
Blogging Platform API – CRUD articles with JWT auth.
Real-time Chat Application – Using
socket.io.File Upload Service – With validation and storage.
E-commerce Backend – Product management, cart, orders.
IoT Logger API – REST API storing sensor data with timestamps.
✅ Tech Stack
Node.js (v18+)
Express.js
MongoDB / Mongoose, PostgreSQL
Jest, Supertest
Docker, PM2, Socket.io
JWT, bcrypt, dotenv
