layout: false .left-column[
] .right-column[ Heroku is a Platform as a Service(PaaS)
- Supports numerous languages
- Relatively simple and easily customizable build process
- Very stable and mature support for Node.js
- Deploys via
git push master - However comes with several notable restrictions
- Nothing can be persisted to disk between deploys
- No access to the box (SSH) ]
- npm install
- npm install
- Shutdown the previous version (connections will queued and held open)
- npm install
- Shutdown the previous version (connections will queued and held open)
- Launch the new service
- npm install
- Shutdown the previous version (connections will queued and held open)
- Launch the new service
- Connections will be routed to the new instance
web: node index.js
- Declares which version of node you require
"engines": {
"node": "4.1.1"
}
- Declares which version of node you require
- Specifies your dependencies for Heroku
- Move any slow build steps the 'npm install' process
- Move any slow build steps the 'npm install' process
...
"scripts": {
"start": "node index.js"
"postinstall": "babel -d dist server"
},
- Move any slow build steps the 'npm install' process
...
"scripts": {
"start": "node index.js"
"postinstall": "babel -d dist server"
},
- Ensure that the launching of the new service is fast
- Connections are paused until the new service starts listening on the assigned port
Two ways to accomplish adding Babel to your Heroku app
require('babel/register')- Prebuild the JavaScript files in the 'postinstall' step
index.js
require('babel/register');
server = require('./server');
package.json
"scripts": {
"postinstall": "make build",
"start": "node index.js"
},
Makefile
build: clean babel
clean:
rm -rf build
mkdir -p build
babel:
babel -d build server/index.js
rsync -av --include \*/ --include \*.json --exclude \* ./server/ ./build/server/
rsync -av --include \*/ --include \*.ejs --exclude \* ./server/ ./build/server/
.PHONY: build clean