node.js http request module code example

Example 1: how to use request module in node js

const request = require('request');
request('http://www.google.com', function (error, response, body) {
  console.error('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});

Example 2: http module in nodejs

//HTTP MODULE NODE.JS
var http = require('http');
var server = http.createServer(function(req, res){
  //write code here
});
server.listen(5000);