NODE JS cancel request
javascript, node.js
Solution
To add to @Etai's answer, you need to require the request module before using it for one instance of the request. Something like this:
var request = require('request');
// ...
// then later in the code
var urlrequest = request.get(uri, function(err, response, body) {
// process data here
});
// later, you'd abort this as:
urlrequest.abort();
Note that I'm saving the instance with `var urlrequest = request.get(params, callback);` so that I can call abort on it later.
Problem
I am using this code to download files in node js : ``` var currentVideoRequest = null; window.spawnVideoPlayer = function (url, subs, movieModel,tag) { if(currentVideoRequest) { try { currentVideoRequest.abort(); } catch(err) { alert(err.message); } } var fs = require('fs'); var urlrequest = currentVideoRequest = require('request'); urlrequest.get({url: url, encoding: 'binary'}, function (err, response, body) { fs.writeFile(FILEURL, body, 'binary', function(err) { }); }); } ``` And in the `currentVideoRequest.abort();` i get this error: ``` Object function request(uri, options, callback) { if (typeof uri === 'undefined') throw new Error('undefined is not a valid uri or options object.') if ((typeof options === 'function') && !callback) callback = options if (options && typeof options === 'object') { options.uri = uri } else if (typeof uri === 'string') { options = {uri:uri} } else { options = uri } options = copy(options) if (callback) options.callback = callback var r = new Request(options) return r } has no method 'abort' ```