How to use request module in node js

node js

The request module is similar to http module. The syntax for installing this module is

npm install request --save

Include this module by using below syntax.

var request = require('request');

the syntax for request 

	var headers = {
		'User-Agent':       'Super Agent/0.0.1',
		'Content-Type':     'application/x-www-form-urlencoded'
	var options = {
		url: 'URL',
		method: 'POST',
		headers : headers,
		form: {'KEY1': 'VALUE1', 'KEY2' : 'VALUE1'}
	request(options, function (error, response, body) {
		console.log('   response.statusCode  '+response.statusCode);
		if (!error && response.statusCode == 200) {
			// Print out the response body
			var body = JSON.parse(body);	
			console.log('   error   '+ error);


You might also like:

Functions in javascript

25-05-2018 functions javascript es5 es6 arrow functions named functions Closures Nested Functions Callbacks Arrow functions.

Example for Conditional Operator in php

16-04-2017 php Conditional Operator example

How to insert bulk information into database in single query execution

18-03-2017 insert sql bulk database

Filter for change Date format (MM-dd-yyyy) in Angular Js

05-03-2017 mm-dd-yyyy date formats angular js

Email validation regular expression in javascript

22-02-2017 email validation regex