Can you create Http Server in Nodejs, explain with code

Answer

Yes, we can create Http Server in Nodejs. We can use http-server command to do so.

Code :

var http = require('http');
var requestListener = function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello You\n');
}

var server = http.createServer(requestListener);
server.listen(8080); // The port where you want to start with.

All node.js Questions

Ask your interview questions on node-js

Write Your comment or Questions if you want the answers on node-js from node-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---