How to upload file by using request module

18-03-2017 request module node js

In request module we are sending files by using below code. The syntax for installing request module is

npm install request --save

Include this module by using below syntax.

var request = require('request');

the syntax for request module to send files

	var fname = 'sample.pdf';
	var options = {
		method: 'POST',
		url: 'URL',
			'postman-token': '8252bb2f-6b2a-657b-b43c-6054fc47c84e',
			'cache-control': 'no-cache',
			'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' 
			File-Name: 'sample',
				value : fs.createReadStream(fname),
				options : { filename: fname, contentType: null } 
	request(options, function (error, response, body) {
		if (!error && response.statusCode == 201) {
			var responses = JSON.parse(response.body);
			console.log('Error File Uploading');


You might also like:

How to search text in string using php ?
29-10-2017 php search string search
How to submit form using javascript or jquery.
16-04-2017 javascript jquery submit form
How to get current date and time (yyyy-mm-dd H:i:s) using javascript
09-03-2017 javascript date time
Get next date from given date in javascript
06-03-2017 date javascript next date
Email validation regular expression in javascript
22-02-2017 email validation regex