0% found this document useful (0 votes)
8 views2 pages

NodeJS Classes Beginner To Advanced

This document is a beginner to advanced guide on Node.js and Express.js, starting with an introduction to Node.js as a JavaScript runtime for server-side programming. It covers the benefits of Node.js, including its speed, lightweight nature, and the use of JavaScript for both client and server. Additionally, it explains Node.js modules and the file system operations such as reading, writing, appending, and deleting files.

Uploaded by

siva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

NodeJS Classes Beginner To Advanced

This document is a beginner to advanced guide on Node.js and Express.js, starting with an introduction to Node.js as a JavaScript runtime for server-side programming. It covers the benefits of Node.js, including its speed, lightweight nature, and the use of JavaScript for both client and server. Additionally, it explains Node.js modules and the file system operations such as reading, writing, appending, and deleting files.

Uploaded by

siva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Node.js & Express.

js Beginner to Advanced Guide

Lesson 1: Introduction to Node.js

What is Node.js?
- Node.js is a JavaScript runtime built on Chrome's V8 engine.
- It allows you to run JavaScript on the server side.

Benefits:
- Fast and lightweight
- Single language (JavaScript) for both client and server
- Asynchronous and non-blocking

Example: Basic Node Server


----------------------------
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("Hello from Node.js server!");
});
server.listen(3000, () => console.log("Server running at http://localhost:3000"));

Lesson 2: Node.js Modules & File System

Modules in Node.js:
- Built-in modules (e.g., fs, http, path)
- Custom/user-defined modules
- Third-party modules (via npm)

Creating a module:
----------------------------
math.js:
function add(a, b) { return a + b; }
module.exports = { add };

app.js:
const math = require('./math');
console.log(math.add(2, 3));

FS Module (File System):


----------------------------
Read File:
fs.readFile("file.txt", "utf-8", (err, data) => { ... });

Write File:
fs.writeFile("file.txt", "Hello", (err) => { ... });

Append File:
Node.js & Express.js Beginner to Advanced Guide

fs.appendFile("file.txt", "More text", (err) => { ... });

Delete File:
fs.unlink("file.txt", (err) => { ... });

You might also like