0

I have a clone of the repository https://github.com/ibnclaudius/express-mongoose-es6-rest-api, I want to deploy to Heroku. In the deployments instructions are written as follows:

# compile to ES5
1. npm run build or gulp

# upload dist/ to your server
2. scp -rp dist/ user@dest:/path

# install production dependencies only
3. npm i --production

# Use any process manager to start your services
4. pm2 start dist/index.js

In production you need to make sure your server is always up so you should ideally use any of the process manager recommended here. We recommend pm2 as it has several useful features like it can be configured to auto-start your services if system is rebooted.

I'm not sure how to proceed. How can I deploy as recommended but in the context of Heroku? I tried to send through the Heroku CLI but did not succeed.

What I tried:

npm run build
cd dist/
git init
heroku git:remote -a farm-rooster
git add .
git commit -am "Início"
git push heroku master

The application log:

2016-10-09T23:33:33.364424+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:

2016-10-09T23:33:33.364648+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:

2016-10-09T23:33:33.364968+00:00 app[web.1]: npm ERR! npm owner ls express-mongoose-es6-rest-api

2016-10-09T23:33:33.365079+00:00 app[web.1]: npm ERR! There is likely additional logging output above.

2016-10-09T23:33:33.368518+00:00 app[web.1]:

2016-10-09T23:33:33.368965+00:00 app[web.1]: npm ERR! Please include the following file with any support request:

2016-10-09T23:33:33.369132+00:00 app[web.1]: npm ERR!
/app/npm-debug.log

2016-10-09T23:33:33.469487+00:00 heroku[web.1]: State changed from starting to crashed

2016-10-09T23:33:33.457348+00:00 heroku[web.1]: Process exited with status 1

2016-10-09T23:33:35.414253+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=farm-rooster.herokuapp.com request_id=e88f1c0e-4ea5-4610-82d6-b437bf37ea0e fwd="186.203.235.191" dyno= connect= service= status=503 bytes=

2016-10-09T23:33:36.117238+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=farm-rooster.herokuapp.com request_id=c8859482-b508-4e93-b9dc-3455558d13ed fwd="186.203.235.191" dyno= connect= service= status=503 bytes=

7
  • Are you using heroku's free or paid plans? Commented Oct 9, 2016 at 23:22
  • Free, but what is the difference? Commented Oct 9, 2016 at 23:23
  • Free dynos sleep after 30mins but I realized this is insignificant in your case Commented Oct 9, 2016 at 23:26
  • Can you update your question with the error you get when deploying using the CLI? Commented Oct 9, 2016 at 23:28
  • I'm currently developing the application, so I'm in the free plan. When deploy into production will change to a paid plan. I'll update my question. But I have no idea on how to implement the pm2 process manager. Commented Oct 9, 2016 at 23:28

2 Answers 2

0

1 - You could try adding a Procfile to the project before sending it to Heroku. I think it should be like web: npm run start.

2 - You shouldn't send just the dist folder to Heroku, you should send the whole project. Heroku will build it and then run (this is one of Heroku's features btw).

3 - PM2 is suggested so your application is monitored and restarted if it breaks. Heroku will do it for you so I don't think using PM2 here is really useful

Sign up to request clarification or add additional context in comments.

Comments

0

Just to make it clear regarding Procfile and handling /dist folder

Procfile,

To determine how to start your app, Heroku first looks for a Procfile. If no Procfile exists for a Node.js app, we will attempt to start a default web process via the start script in your package.json. So you can either have Procfile or you can define Start section in your package.json. e.g. "start": "node server.js"

/dist folder

You have two options

  1. Push dist folder to heroku along with other application stuff.
  2. Don't push dist and keep it ignored in your gitignore file. Use postintall script in your package.json to create /dist folder "postinstall": "ng build --prod" postinstall script

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.