Home Blog Programming Hello Node

Hello Node

Posted on September 30, 2014 by Edit

Here is a simple example to build web application using nodejs.

  • First install nodejs
  • Implement the below program in a JS file.
  • Now run the program.
    • Go to command line
    • Type >node filename
    • Application start running on given port(Below program runs on 8000 port).
  • Access the application from browser at http://localhost:port (Below program runs at http://localhost:8000)
  • Hit CTRL + C on command line to stop the application
Node JS

Code

// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
Tags : js
This website is made possible by displaying online advertisements to our visitors.
Please consider supporting by disabling your ad blocker.

Get new posts by email:
loading comments...
© 2023 Shivaji Varma. Made in India.