Node.js Learning Module

Node.js Learning Module

Master server-side JavaScript development with this comprehensive learning guide. Build scalable and efficient applications using Node.js and Express.js.

Module Objectives

By the end of this module, learners will be able to:

  • Understand Node.js architecture
  • Work with Node.js modules
  • Build REST APIs
  • Handle asynchronous operations
  • Use Express.js for backend development
  • Connect Node.js with databases

1. Introduction to Node.js 1

Node.js is an open-source, cross-platform runtime environment that allows JavaScript to run on the server.

Features:

  • Built on Chrome V8 Engine
  • Non-blocking & event-driven
  • High performance
  • Scalable applications

2. Node.js Architecture 2

  • Single-threaded
  • Event Loop
  • Asynchronous execution
  • Callback queue

3. Node.js Modules 3

Types of Modules:

  • Core Modules (fs, http, path, os)
  • Local Modules
  • Third-Party Modules (npm)
const fs = require(‘fs’);

4. npm (Node Package Manager) 4

Common Commands:

npm init
npm install express
npm uninstall package-name

5. File System Module (fs) 5

Operations:

  • Read file
  • Write file
  • Append file
  • Delete file
fs.readFile(‘test.txt’, ‘utf8’, callback);

6. HTTP Module 6

Create Server:

const http = require(‘http’);

http.createServer((req, res) => {
  res.write(“Hello Node.js”);
  res.end();
}).listen(3000);

7. Asynchronous Programming 7

Methods:

  • Callbacks
  • Promises
  • Async / Await
async function fetchData() {
  await processData();
}

8. Express.js Framework 8

Why Express?

  • Minimal & fast
  • Simplifies routing
  • Middleware support

Basic App:

const express = require(‘express’);
const app = express();

app.get(‘/’, (req, res) => {
  res.send(‘Welcome to Node.js’);
});

app.listen(3000);

Practice Questions

What is Node.js?
Explain Event Loop.
Difference between blocking and non-blocking?
What is Express middleware?
How does async/await work?