Node.js Topics
Day 26:
- Introduction to Node.js
- Operating System Module
- File System Module
- HTTP Module
- Create Server
App.js
function sayHello(){
return "Welcome to Hema coding School"
}
// module.exports= sayHello;
School = {
name:"Hema",
role:"Student"
}
module.exports = {sayHello, School}
Index.js
const myCall = require('./App.js');
console.log(myCall.sayHello())
console.log(myCall.School)
const os = require("os")
console.log(os.freemem())
console.log(os.totalmem())
const fs = require('fs');
// (file, data, [optional], callback)
fs.writeFile("output", "Welcome to hema coding School", "utf-8", (error)=>{
if(error){
console.log(error)
}
else{
console.log("file has created successfully")
}
})
// path, [optional], callback
fs.readFile("./output","utf-8",(error,data)=>{
if(error){
console.log(error)
}
else{
console.log(data)
}
})
const http = require('http');
const server = http.createServer((req,res)=>{
res.writeHead(200,{"Content-Type": "text/plain"})
res.end("Welocme hema coding school")
})
// PORT, HOSTNAME, BACKLOG, CALLBACK
const PORT = 3000;
const HOSTNAME = "127.0.0.1";
const BACKLOG = 551;
const CALLBACK = ()=>{
console.log(`Server has started http://${HOSTNAME}:${PORT}`)
}
server.listen(PORT, HOSTNAME, BACKLOG, CALLBACK);
Interview Questions:
1. Explain the key features of Node.js?
2. What is the purpose of the Operating System Module in Node.js?
3. What is the role of the fs.createReadStream and fs.createWriteStream methods?
4. Explain the process of creating an HTTP server in Node.js?
No comments:
Post a Comment