Skip to content

Instantly share code, notes, and snippets.

@acidtib
Forked from evenchange4/step.md
Created September 12, 2020 21:02
Show Gist options
  • Save acidtib/0dd18232a89b865f8a65d33b1bd4a047 to your computer and use it in GitHub Desktop.
Save acidtib/0dd18232a89b865f8a65d33b1bd4a047 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

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