Heroku Deployment
Resources:
- https://devcenter.heroku.com/articles/getting-started-with-nodejs
- https://howtonode.org/deploy-blog-to-heroku
Getting Started on Heroku with Node.js
brew install heroku/brew/heroku- We have to install Heroku first. (run this command from Terminal (Mac OS))
heroku login- Command opens your web browser to the Heroku login page
heroku create- Command creates an app on Heroku, which prepares Heroku to receive source code
git push heroku main- Command deploys your code
heroku ps:scale web=1- Command ensures that at least one instance of the app is running
heroku open- Command allows to visit deployed app
View logs
Heroku treats logs as streams of time-ordered events aggregated from the output streams of all your app and Heroku components, providing a single channel for all of the events.
heroku logs --tail- Command allows to view information about running app
Define a Procfile
Use a Procfile, a text file in the root directory of your application, to explicitly declare what command should be executed to start your app.
web: npm start- Command declares a single process type, web, and the command needed to run it.
Scale the app
Right now, your app is running on a single web dyno. We can think of a dyno as a lightweight container that runs the command specified in the Procfile.
- ` heroku ps`
- Command checks how many dynos are running
- By default, app is deployed on a free dyno. Free dynos will sleep after a half hour of inactivity (if they don’t receive any traffic)
heroku ps:scale web=0- Scaling an application on Heroku is equivalent to changing the number of dynos that are running.
Run the app locally
heroku local web- Just like Heroku, heroku local examines the Procfile to determine what to run.
- http://localhost:5000 (app should run locally)
ACP for Heroku
git add .git commit -m " "git push heroku main