top button
Flag Notify
Site Registration

How to create a web server in node.js?

0 votes
357 views
How to create a web server in node.js?
posted Aug 26, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Command name is createServer and here is sample code -

File: myfile.js

var http = require("http");
var server = http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/html"});
  response.write("<!DOCTYPE "html">");
  response.write("<html>");
  response.write("<head>");
  response.write("<title>Hello World Page</title>");
  response.write("</head>");
  response.write("<body>");
  response.write("Hello World!");
  response.write("</body>");
  response.write("</html>");
  response.end();
});

server.listen(80);
console.log("Server is listening");

Start the server

node myfile.js

Now connect to server as http://localhost or http://127.0.0.1 from the browser.

answer Aug 26, 2014 by Salil Agrawal
Similar Questions
0 votes

I am new to node.js. I heard node.js is a web server. So Just i want to know node.js is similiar to apache server?

+1 vote

Hi ,

I am new to node js
Can one please help me , how one user can join in more than one room and he can chat at a time without destroying another room.

+1 vote

Any pointer on how to install Node.js in Fedora?

...