Node JS - Server


Node Js has built in http module, which allow us t create an instance of server.

There is another way to create a server which external npm package express provides.


Using core Node http module

const http = require("http");

const server = http.createServer((reqres=> {
  res.end("Welcome Node");
});

server.listen(80);



Now run this file using node command

node file.js

And can navigate to the browser http://localhost:3000


Using express package

const express = require("express");

const app = express();

app.get("/", (reqres)=>{
    res.send("Welcome Node");
})

app.listen(80);