First application for node.js

Before start you need the following two saftwares available on your computer,a>Text Editor b>The Node.js binary  installables.node

Download latest version of Node.js installable archive file from  https://nodejs.org/download/ui

creating node.js aplication:server

step1:Inport Require Moduleget

var http = require("http");

step2:create serverit

Read request and return responseio

http.createServer(function (request, response) {
   // Send the HTTP header 
   // HTTP Status: 200 : OK
   // Content Type: text/plain
   response.writeHead(200, {'Content-Type': 'text/plain'});
   
   // Send the response body as "Hello World"
   response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');

step3:Testing Request&Responseconsole

$ node main.js
Server running at http://127.0.0.1:8081/

Console Output 「Hello World」 function

Congratulations, running success;test

相關文章
相關標籤/搜索