Hi all, I am new to node.js and express.js
I am having little bit confusion on creating server on node.js and express.js.
In Node.js we use the http module to create a server.
where as in express we don't use any http module, still we are able to create a server. How server is created here ? Is app.get() is creating it ?
I tried to google the difference but couldn't get the right explanation, pls someone help me here or share a link for a document so, I can understand it better.
// creating server using Node.js
var http = require('http');
var fs = require('fs');
var htmlData;
fs.readFile('index.html',(err, data)=>{
if(err) throw err;
htmlData = data;
});
http.createServer(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(htmlData); //read the file & write the data content
res.end();
}).listen(8000,()=>{console.log("PORT is 8000")});
// creating server using Express.js
const express = require('express');
const fs =require('fs');
const app = express();
let htmlData;
fs.readFile('index.html','utf-8',(err,data)=>{
htmlData = data;
})
app.get('/',(req,resp)=>{
resp.writeHead(200,{'content-type':'text/html'}).write(htmlData).end();
}).listen(8000);