Skip to content

Instantly share code, notes, and snippets.

@evenchange4
Created September 23, 2012 21:55
Show Gist options
  • Save evenchange4/3773179 to your computer and use it in GitHub Desktop.
Save evenchange4/3773179 to your computer and use it in GitHub Desktop.
Deploy a Express.js project on Heroku

Deploy a Express.js project on Heroku

Step by step from command line by Michael Hsu

Quick start

Create a Node.js web framework 'express'

$ express myfirstexpress && cd myfirstexpress

Declare dependencies with NPM /package.json

# /package.json
{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "express": "3.0.0rc4",
    "jade": "*"
  },
  "engines": {
    "node": "0.8.x",
    "npm": "1.1.x"
  } 
}

Install your dependencies (-l 處理相依性)

$ sudo npm install -l

Declare process types with Procfile

# create '/Procfile'
web: node app.js

# test start
$ foreman start

Git

$ git init
$ git add .
$ git commit -m "init"

Create Heroku app

$ heroku create myfirstexpress

Deploy on Heroku

$ git push heroku master

Run server

$ heroku ps:scale web=1
Scaling web processes... done, now running 1

# check server
$ heroku ps
=== web: `node app.js`
web.1: up for 10s

Open

$ heroku open
http://myfirstexpress.herokuapp.com/

Reference

Getting Started with Node.js on Heroku

@rainb3rry
Copy link

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment