简体   繁体   中英

how to solve MEAN stack app deploy on heroku give error?

after build of angular app with api node.js, deploy of heroku give following error. but when i run my app in localserver it works perfectly with no errors.

this is my heroku logs

C:\Users\PC>heroku logs -a=ts-ecommerce-project
2020-07-16T10:55:21.649783+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ts-ecommerce-project.herokuapp.com request_id=568f7b4d-43b3-455b-803c-6e57b76e79be fwd="106.207.242.158" dyno= connect= service= status=503 bytes= protocol=https
2020-07-16T10:55:22.206857+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ts-ecommerce-project.herokuapp.com request_id=bd96231e-5998-4eef-9b3b-9531bda070fc fwd="106.207.242.158" dyno= connect= service= status=503 bytes= protocol=https
2020-07-16T11:03:30.717571+00:00 app[api]: Rollback to v9 by user it171056@global.org.in
2020-07-16T11:03:30.717571+00:00 app[api]: Release v11 created by user it171056@global.org.in
2020-07-16T11:03:32.639092+00:00 heroku[web.1]: State changed from crashed to starting
2020-07-16T11:03:35.769681+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-16T11:03:38.672581+00:00 app[web.1]:
2020-07-16T11:03:38.672611+00:00 app[web.1]: > backend@0.0.0 start /app
2020-07-16T11:03:38.672612+00:00 app[web.1]: > node ./bin/www
2020-07-16T11:03:38.672612+00:00 app[web.1]:
2020-07-16T11:03:39.310220+00:00 app[web.1]: Port 80 requires elevated privileges
2020-07-16T11:03:39.318242+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-07-16T11:03:39.318623+00:00 app[web.1]: npm ERR! errno 1
2020-07-16T11:03:39.320174+00:00 app[web.1]: npm ERR! backend@0.0.0 start: `node ./bin/www`
2020-07-16T11:03:39.320401+00:00 app[web.1]: npm ERR! Exit status 1
2020-07-16T11:03:39.320636+00:00 app[web.1]: npm ERR!
2020-07-16T11:03:39.320820+00:00 app[web.1]: npm ERR! Failed at the backend@0.0.0 start script.
2020-07-16T11:03:39.320988+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-07-16T11:03:39.328462+00:00 app[web.1]:
2020-07-16T11:03:39.328701+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-07-16T11:03:39.328843+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-07-16T11_03_39_323Z-debug.log
2020-07-16T11:03:39.392239+00:00 heroku[web.1]: Process exited with status 1
2020-07-16T11:03:39.429206+00:00 heroku[web.1]: State changed from starting to crashed
2020-07-16T11:03:39.431919+00:00 heroku[web.1]: State changed from crashed to starting
2020-07-16T11:03:42.993576+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-16T11:03:47.260974+00:00 app[web.1]:
2020-07-16T11:03:47.260994+00:00 app[web.1]: > backend@0.0.0 start /app
2020-07-16T11:03:47.260994+00:00 app[web.1]: > node ./bin/www
2020-07-16T11:03:47.260995+00:00 app[web.1]:
2020-07-16T11:03:48.222470+00:00 app[web.1]: Port 80 requires elevated privileges
2020-07-16T11:03:48.244977+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-07-16T11:03:48.245462+00:00 app[web.1]: npm ERR! errno 1
2020-07-16T11:03:48.246678+00:00 app[web.1]: npm ERR! backend@0.0.0 start: `node ./bin/www`
2020-07-16T11:03:48.246926+00:00 app[web.1]: npm ERR! Exit status 1
2020-07-16T11:03:48.247101+00:00 app[web.1]: npm ERR!
2020-07-16T11:03:48.247244+00:00 app[web.1]: npm ERR! Failed at the backend@0.0.0 start script.
2020-07-16T11:03:48.247392+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-07-16T11:03:48.446363+00:00 app[web.1]:
2020-07-16T11:03:48.446697+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-07-16T11:03:48.446859+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-07-16T11_03_48_248Z-debug.log
2020-07-16T11:03:48.508496+00:00 heroku[web.1]: Process exited with status 1
2020-07-16T11:03:48.562957+00:00 heroku[web.1]: State changed from starting to crashed

this is my config.js file config.js

// check env.
var env = process.env.NODE_ENV || 'development';
// fetch env. config
var config = require('./config.json');
var envConfig = config[env];
// add env. config values to process.env
Object.keys(envConfig).forEach(key => process.env[key] = envConfig[key]);

and this is my config.json file config.json

{
    "development": {
        "PORT": 3000,
        "MONGODB_URI": "mongodb://localhost:27017/MEANStackDB",
        "JWT_SECRET": "SECRET#123",
        "JWT_EXP": "1h"
    },
    "production": {
        "PORT": 80,
        "MONGODB_URI": "mongodb://xxxxx/DB_Name",
        "JWT_SECRET": "SECRET#123",
        "JWT_EXP": "1h"
    }
}

currently i set my project for development mode which is run on port 3000

Add this to your app.js or server.js file.

Heroku sets the PORT variable that you are supposed to bind.

const PORT = process.env.PORT || 80;

app.listen(PORT, () => console.log(`Server is listening on port ${PORT}...`));

You cannot use port 80 on heroku. Please set the port that you are listening on in your code like this:

port = process.env.PORT || 80

Heroku should automatically set up the proxy so that your URL on port 80 redirects to the port that it sets in process.env.PORT .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM