We learned necessary concepts to write our first web application in nodejs. Lets dive in.
Steps
1. Create a file called "myserver.js". Import the required module(What module is required? http which is used to create a web server)
var http = require("http");
2. Create a server
var http = require('http'); // step1
//step2
http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type':'text/plain'}); // it tells that what kind of content will be delivered to the browser
response.end('Welcome to Nodejs'); // Write the content and close the connection
}).listen(8082);
console.log('Web server running at http://localhost:8082/');
3. Run a program
node myserver.js
You could see the console log
Web server running at http://localhost:8082/
goto web browser and type http://localhost:8082 in the address bar. you will see the message "Welcome to Nodejs"