Unit-1: Node JS
framework: Framework wo hota h jha hum khud ka logic likh sakte Hain kuchh set of
rules hamen follow karne padte Hain.
Library prebuilt functions hum use kr sakte h like shorting and stack data structures. If
we take example of C++ we use stl functions.
html and css browsers the engines pr chalta h.
HTML and CSS Layout Engine pr chalta H har browser ka Apna kudka Layout engine hota
Hai. for example Crome Ka layout engine blink. Firefox ka layout engine gecko and an
edge layout engine Trident. Isi trah JS Ka bhi enginr Hota Hai jise jsengine ya interpreter
kate Hai. Fastest js engine chrome Ka Hota Hai Gise V8 Kehte Hain.
Ryan Dall Ne 2009 Me browser sa interpreter alag kr tha. Or usme file handling ad kar
diya tha. use hi node js kehte h.
Non blocking
Node Setup
- npm init -y
Inbuild modules in NODEJS
http module
const http = require('http');
const server = [Link]((req, res ) => {
[Link]("Hello World from NODE JS");
[Link]();
});
[Link](3000, () => {
[Link]("Server in running");
})
Path Module
const path = require('path');
const filePath = [Link](__dirname, '[Link]');
Fs Module in NODEJS
const data = {
name: 'John Doe',
age: 30,
city: 'New York'
Promise
[Link](filePath, [Link](data)).
then(() => {
[Link]("Done");
}).catch((err) => {
[Link](err);
})
Callback
[Link](filePath, [Link](data), (err) => {
if(err) {
[Link](err);
} else {
[Link]("Done");
})
async function writeFile() {
try {
await [Link](filePath, [Link](data));
[Link]("Done");
} catch(err) {
[Link](err);
writeFile();
async function writeFile() {
try {
await [Link](filePath);
[Link]("Done");
} catch(err) {
[Link](err);
writeFile();
URL Module
const url = require('url');
const myUrl = '[Link]
const parsedUrl = [Link](myUrl, true);
[Link](parsedUrl);
User Define Module
function add(a, b) {
return a + b;
function sub(a, b) {
return a + b;
function div(a, b) {
return a + b;
function mul(a, b) {
return a + b;
// [Link] = {Addition: add, sub};
[Link] = { add, sub, div, mul };
const {add, sub} = require('./maths');
[Link](add(10, 10));
const {Addition, sub} = require('./maths');
[Link](Addition(10, 10));
OS Module
const os = require('os');
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]().length);