Home > OS >  Error in deploying a small nodejs app with heroku
Error in deploying a small nodejs app with heroku

Time:10-24

I have an API server and I want to update the database every one minute so I created a small script(another project) so he will send a request to my main server each minute and I did a route to handle the request

const request = require("request");
setInterval( async()=> { 
   request({
     url :"https://serverdomainname/route",
     json:true
},(err,res,body)=>{
    console.log("sent")
})}, 60000);

In development when I type

Node app everything work but when I deployed in Heroku it worked in the first seconds but then I have this error

{

2021-10-23T16:09:52.503866 00:00 app[web.1]: > updateserver@1.0.0 start /app

2021-10-23T16:09:52.503866 00:00 app[web.1]: > node app.js

2021-10-23T16:09:52.503867 00:00 app[web.1]:

2021-10-23T16:10:51.663197 00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

2021-10-23T16:10:51.709745 00:00 heroku[web.1]: Stopping process with SIGKILL

2021-10-23T16:10:51.846193 00:00 heroku[web.1]: Process exited with status 137

2021-10-23T16:10:51.926528 00:00 heroku[web.1]: State changed from starting to crashed

}

Those the server logs from the Heroku server

Is there a solution or can I just do it from the main server?

CodePudding user response:

Heroku expecting to run your application on a port, you may assign port even don't required like

const request = require("request");
setInterval( async()=> { 
   request({
     url :"https://serverdomainname/route",
     json:true
},(err,res,body)=>{
    console.log("sent")
})}, 60000);

// to run on Heroku
require('http').createServer((req, res) => res.end()).listen(process.env.PORT || 3000);

Or https://stackoverflow.com/a/40621709/3461055 may also help you

  • Related