So I have got into this problem while deploying my website with heroku. I have seen other solutions in which I have tried to change the scripts in package.json and Procfile aswell but no luck for me Please help me. This website runs well locally Here is my index.js main function
app.get("/", function(req, res){
const fact = facts.space
res.render("home", {fact: fact});
});
Here is my listen function.
const port = 3000 || process.env.PORT
app.listen(port, function () {
console.log("@ working");
})
Here is my packages.json packages.json Here is my Procfile Procfile Here is the error that I am getting Error Here are all of my files All files
You need to invert the definition of the port to check first the $PORT
env variable, then fall back to the default port number (3000
) in case it does not exist (ie on local development environment)
const port = process.env.PORT || 3000