Stobor
0
Q:

http server node example

const http = require("http");

const server = http.createServer((req, res) => {
  console.log(req.url);

  if (req.url === "/") {
    res.write("<h1>This is home page</h1>");
  } else if (req.url === "/about") {
    res.write("<h1> This is about page </h1>");
  } else if (req.url === "/contact") {
    res.write("<h1>This is contact page</h1>");
  } else {
    res.write("<h1>Page not found</h1>");
  }
  
  res.end();
});

server.listen(3000, () => {
  console.log("server is running");
});
1
var http = require('http');

//create a server object:
http.createServer(function (req, res) {
  res.write('Hello World!'); //write a response to the client
  res.end(); //end the response
}).listen(8080); //the 
2

New to Communities?

Join the community