Oleg Rovenskyi
April, 2017
// OS X Homebrew:
$ brew install heroku
// Windows:
32-bit - https://cli-assets.heroku.com/branches/stable/heroku-windows-386.exe
64-bit - https://cli-assets.heroku.com/branches/stable/heroku-windows-amd64.exe
// Debian/Ubuntu:
$ sudo apt-get install software-properties-common # debian only
$ sudo add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./"
$ curl -L https://cli-assets.heroku.com/apt/release.key | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install heroku
(Toolbelt)
The Heroku Command Line Interface (CLI), formerly known as the Heroku Toolbelt, is a tool for creating and managing Heroku apps from the command line / shell of various operating systems.
Heroku provides you with virtual "Dyno" that launches your application. In short, one dyno means one running instance of your application.
Web: Web dynos are dynos of the “web” process type that is defined in your Procfile. Only web dynos receive HTTP traffic from the routers.
Worker: Worker dynos can be of any process type declared in your Procfile, other than “web”. Worker dynos are typically used for background jobs, queueing systems, and timed jobs. You can have multiple kinds of worker dynos in your application. For example, one for urgent jobs and another for long-running jobs. For more information, see Worker Dynos, Background Jobs and Queueing.
Dyno types
Heroku provides a number of different dyno types each with a set of unique properties and performance characteristics. Free, Hobby, Standard and Performance dynos.
Scalability
To scale horizontally (scale out), add more dynos. For example, adding more web dynos allows you to handle more concurrent HTTP requests
To scale vertically (scale up), use bigger dynos. The maximum amount of RAM available to your application depends on the dyno type you use.
The first option:
web: node ./dist/server/bin/www.js
2. Deploy the app
$ heroku login
$ heroku create
or
$ heroku create <name app>
$ git push heroku master
$ heroku ps:scale web=1
$ heroku open
3. View logs
$ heroku logs --tail
$ git clone https://github.com/vladotesanovic/angular2-express-starter
$ cd angular2-express-starter
1. Prepare the app
Scale the app:
1. Check how many dynos are running
$ heroku ps
2. Scale
$ heroku ps:scale web=0 // off app
$ heroku ps:scale web=1
Update project:
1. Add some changes
2. Fix changes
$ git add .
$ git commit -m "Demo"
$ git push heroku master
$ heroku open
3. Additional https://github.com/heroku/heroku-repo
The second option. When we don't have server:
1. Prepare the app
$ https://github.com/angular/angular-cli //open
$ npm install -g @angular/cli
$ ng new PROJECT-NAME
$ cd PROJECT-NAME
2. Edit package.json
"scripts": {
...
"heroku-prebuild": "npm install -g http-server",
"heroku-postbuild": "ng build --prod",
"start": "http-server dist/"
},
"dependencies": {
...
moved here these devDependencies
"@angular/cli": "1.4.4",
"@angular/compiler-cli": "^4.2.4",
"@angular/language-service": "^4.2.4",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"typescript": "~2.3.3"
},
or
$ heroku config:set NPM_CONFIG_PRODUCTION=false
3. Deploy app
$ heroku login
$ heroku create
or
$ heroku create <name app>
// fix changes
$ git add .
$ git commit -m "Demo"
// deploy to heroku
$ git push heroku master
$ heroku open
1. Timer
var http = require("http");
setInterval(function() {
http.get("http://<your app name>.herokuapp.com");
}, 300000); // every 5 minutes (300000)
2. Simple setInterval
3. KeepAwake is a site that pings your free Heroku apps for you.
https://keep-awake.herokuapp.com/
4. If you install the NewRelic Heroku Addon you can set up availability monitoring. You provide a URL which NewRelic pings every 30 seconds, therefore keeping your app awake.
5. Pingdom, Uptime Robot, Kaffeine
1. $ git clone https://github.com/dynamis/heroku-clock
2. create app
$ heroku create <app name>
3. edit clock.rd
ping_uri_list = [
"https://ts-heroku.herokuapp.com/"
]
4. $ git add .
$ git commit -m "msg"
$ git push heroku master
5. $ heroku ps:scale clock=1
deploy from github
heroku local web
$ git clone https://github.com/heroku/node-js-getting-started.git
$ cd node-js-getting-started
$ npm i
$ heroku local web
addons: These are applications developed by third-party developers. They can be conveniently embedded in your own
$ heroku addons
$ heroku addons:add newrelic:standard
web-interface: https://devcenter.heroku.com/articles/managing-add-ons
New Relic - Is an application that monitors and analyzes your application
PGBackups -This addon allows you to backup your database
SendGrid - Is a postal service
More addons: Heroku Addons Center