Request for /index.htm is available.
To create a Web Client, you can also use http Module. Here is an example.
Create client.js with the following content:
var http = require ( 'http' ); // Tao doi tuong options to use Request var options = { host : 'localhost' , port : '8081' , path : '/index.htm' }; // Callback can be used to respond Response var callback = function ( response ) { // Update the data to Stream var body = '' ; response . on ( 'data' , function ( data ) { body + = data ; }); response . on ( 'end' , function () { // Ket via the user console . console . log ( body ); }); } // Create a request toi Server var req = http . request ( options , callback ); req . end ();
Run client.js on another Terminal screen to see the result:
$ node client . js
Check the result:
Travel Web Module in Node.js
Hello World!
Then check the results on the Server.
Server is currently running: http://127.0.0.1:8081/
Request for /index.htm is available.
According to Tutorialspoint
Previous article: Utility Module in Node.js
Next article: Express Framework in Node.js