Hello Node
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
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/");
-
Previous -
Next
This website is made possible by displaying online advertisements to our visitors.
Please consider supporting by disabling your ad blocker.
Please consider supporting by disabling your ad blocker.
loading comments...