Celebrating 80th Independence Day of India• Jai Hind •Bharat Mata Ki Jai• Jai Hind •Long Live India• Jai Hind •Jai Hind• Jai Hind •

Why we should use Node Js

Ashutosh Anand Tiwari
By Ashutosh Anand TiwariPublished Nov 9, 2024 · 2 min read
Why we should use Node Js

JS browser ke bahar bhi bahut kuchh kar sakti hai, chalo kuch examples dekhte hain.”

const fs= require('fs');
fs.writeFileSync('hello.txt','Aur kaise ho??')
const text= fs.readFileSync('hello.txt')
console.log("text read", text);

FS ke bahut saare methods hain, bas itna samajh lijiye ki JavaScript Node.js me file delete, write, edit, aur create kar sakti hai. Aage hum isko detail me padhenge. Hum kisi bhi application ko bhi open kar sakte hain, jaise ab ek example dekhte hain kaise Chrome ko open karein.

const {exec}= require('child_process')

exec('start chrome')

Networking capabilities

JS Node.js me server bhi start kar sakti hai. Ek file banao aur usme likho

const http= require('http')

const server= http.createServer((req,res)=>{
  res.end("hello world")
})

server.listen('3000')

// isko krne ke baad terminal me node script.likho 
// debugger se on kro
// browser pe jaake localhost:3000 hit kro
// browser me aisaa dikhega

image.png

Server ka code debug se run karne ke liye, aap left top pe green play button ko click kar sakte hain. Dhyan rahe, aapke launch.json file me ye code hona chahiye. Yani, program me aapke file ka naam hona chahiye. Mere file ka naam script.js hai, to maine script likha hai

  // .vscode/launch.json
  "version": "0.2.0",
  "configurations": [

    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "program": "${workspaceFolder}\\server.js"
    }
  ]
}
  • Process management kr sakte hain
  • Operating system se interact kr sakte hain node js se

aur bahut saari cheeje ….

Continue Exploring

Profile

Ashutosh Anand Tiwari

Follow

Writer & curator of this digital garden — open notes for learners worldwide.

Request a Topic

Want me to write notes on a course?

Tell me the course, book, or research topic you want covered. If it helps learners, I'll consider adding structured digital notes for it in the garden.

Collaborate

Have a notes collection to feature here?

Do you have open notes you want featured in this digital garden? Let me know — we can collaborate and publish them for learners worldwide.