Hi, there is this following code which I'd like to bring the request part out of "
app.post", store it in a separate file and call it whenever needed.
I have tried the export method but I was keep getting the undefined for "req" and "res".
app.post('/hook', function (req, res) {
url = "https://MY_URL",
// ( request part )
// I'd like to store following to a separate file
// and call it from main file whenever needed.
request({url : url, headers : {"Authorization" : auth}},
function (error, response, body) {
parseString(body, function (err, result) {
try {
return res.json({
"SOME_JSON": "JSON"
});
} catch (err) {
console.error("no request!", err);
}
});
});
// end request
});
a help on this would be greatly appreciated.