node js = (google chrome's engine created in c++) V8 engine + javascript repper code
- install node js for your os
- check the installation if err
- get basic understanding of npm "nahi pta mujhe"
- create new node js file with the command
npm init
npm init -y
- understand how to read out the docs go to nodejs.org/docs
- be familiar with moduls like
// file system, http, many more;
const fs = require("fs");
- you can write/create a file
fs.writeFile("filename.ext","data",callback(err));
callback for handle error in between the process.
- appending text to the file
fs.appandFile("filename.ext","data",callback(err));
- rename file
fs.rename("filename.ext","newNameToFile",callback(err));
- copy file
fs.copyFile("firstfilenameOrPath","secondfilenameOrPath",callback(err));
Data of first file will be copied into the second file if everything heppn correctly or it will show specific error message.
- deleting a file
fs.unlink("filename.ext",callback(err));
- deleting an empty directory (we can use "rm" or "rmdir")
fs.rm("directorypath",callback(err));
- deleting a directory with files (we can use "rm" or "rmdir")
fs.rm("directorypath",{recursive:true},callback(err));
this recursive is an optional argument, which is importent for delete the directory with files.
const http = require('http');
- creating server with the help of HTTP module of node js
//server via http method ✅
const http = require('http');
http.createServer((req,res)=>{
res.writeHead(200,{content_type:"plane/text"});
res.end("hello sir ... server is created by traditional http method");
}).listen(3000,()=>{
console.log('on http://localhost:3000/');
})
- installing npm packeges
npm install packegename
or we can only use i to indicate install keyword
- uninstalling npm packeges
npm uninstall packegename
- installing particular version for specific packege
npm i packegename@version
whenever you install any packege for particular work, it will install another required packeges for proper functioning of that packege into node module folder as well.
-
Dependencies : are these packeges & another required packeges for proper functioning of the application.
-
Devdependencies : are those packeges, which are used in development phase only.
- create a server with express in an easy way then http method
// server via express method ✅
const express = require("express")
const app = express()
app.get("/",(req,res)=>{
res.send("hello sir.. server is created by express")
}).listen(3000,()=>{
console.log("check on http://localhost:3000");
})