0

My heroku app does not work.

When i try to deply my heroku app it says: Web process failed to bind to $PORT within 60 seconds of launch

This is the code

`

const express = require('express');
const app = express();
const port = 1113;
const fileUpload = require('express-fileupload');

//dotnev
require('dotenv').config();
//connect to mongo db
const mongoose = require('mongoose');
mongoose.connect(process.env.DB_STRING, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
    console.log("MongoDB connected");
})
.catch(err => console.log(err));

//set ejs
app.set('view engine', 'ejs');
//url encoded
app.use(express.urlencoded({ extended: true }));
// expres static
app.use('/static', express.static('static'))
//app.use file upload
app.use(fileUpload());
//import routes
const routes = require('./routes/routes.js');
app.use('/', routes);
app.listen(5000 || process.env.PORT,() => console.log(`Example app listening on port !`));

`

And this is the error

2022-11-02T17:29:53.123252+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 2022-11-02T17:29:53.199406+00:00 heroku[web.1]: Stopping process with SIGKILL 2022-11-02T17:29:53.405101+00:00 heroku[web.1]: State changed from starting to crashed 2022-11-02T17:29:53.347721+00:00 heroku[web.1]: Process exited with status 137

  • TL;DR: your `||` is backwards. `process.env.PORT` needs to come first, not second. Try it: `undefined || 5000`, `1234 || 5000`. Compare that with `5000 || undefined` and `5000 || 1234`. – ChrisGPT was on strike Nov 02 '22 at 19:00

0 Answers0