I need to add a delay to an API call so I'm using setTimeout
. After 2 seconds on success, I need to return res.status(200).json(response)
.
exports.someEndpoint = function(req, res) {
return request.post({
url: //etc
})
.then(function(response) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
// is this right?
resolve(
res.status(200).json(response);
);
}, 2000);
});
});
};
My question is: do I need to call resolve
inside the setTimeout
? Or can I just completely omit it?