Answer the question
In order to leave comments, you need to log in
How to make a response result of module execution, nodejs/express?
Good afternoon! Please tell me why I can not get to the response? (nodejs / express) I'm trying
to write a module that would receive data from another server ... it receives data, it is displayed in the console, but how to make the response be the result of the execution of this module, so that I can send them further to the client?
It doesn't work out how to do it.
Thank you!
The module itself
var request = require('request');
var rp = require('request-promise');
loadData = () => {
var options = {
uri: 'http://fake-domen.com/...',
headers: {
'User-Agent': 'Request-Promise'
},
json: true // Automatically parses the JSON string in the response
};
rp(options)
.then(function (repos) {
console.log(repos, 'repos');
return repos
})
.catch(function (err) {
// API call failed...
});
}
exports.func = loadData;
Answer the question
In order to leave comments, you need to log in
No way. Neither request nor request-promise can make requests that block an event loop.
loadData = () => {
var options = {
uri: 'http://fake-domen.com/...',
headers: {
'User-Agent': 'Request-Promise'
},
json: true // Automatically parses the JSON string in the response
};
return rp(options)
.then(function (repos) {
console.log(repos, 'repos');
return repos
})
.catch(function (err) {
// API call failed...
});
}
const func = require('./func);
func()
.then()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question