Reputation: 1372
I know this is unorthodox, but I was wondering if there's a way to use a redirect inside of the app.listen, something like this:
app.listen(app.get('port'), function () {
//res.redirect("some url")
})
The fact is I need to launch a GET request after the app is on listen mode, after some research I've found it could be done with a redirect; clearly, I don't have a routing and a response object res to afford it.
How could I achieve this?
Upvotes: 1
Views: 350
Reputation: 13260
You can simply run an http request in your ready handler function.
For instance you could use the request
package:
const request = require('request');
app.listen(app.get('port'), function () {
request('http://your.url', function (error, response, body) {
// do something with the response
});
})
Of coure you'll need to npm i request
in order for the above example to work and you can choose whatever http client you prefer and replace it.
Upvotes: 2