FORSMILE
JA
開発記事2016/01/29

Deploying a Node.js + Express Application to Heroku

Trying to run Aurelia.js in a Node.js and Express environment - Part 6

Back to Blog

Trying to run Aurelia.js in a Node.js and Express environment - Part 1

Trying to run Aurelia.js in a Node.js and Express environment - Part 2

Trying to run Aurelia.js in a Node.js and Express environment - Part 3

Trying to run Aurelia.js in a Node.js and Express environment - Part 4

Trying to run Aurelia.js in a Node.js and Express environment - Part 5

This time, we'll try using Heroku as a free cloud application platform.

Installing heroku-toolbelt

⇒ Download from https://toolbelt.heroku.com/

Download and install Heroku's client tool, heroku-toolbelt, from the link above. This will enable various Heroku commands on your command prompt.

※ I believe Git is included in heroku-toolbelt, but I'm not certain, so you may need to install it if it doesn't work.

Preparing the Procfile

Create a Procfile (no extension) to define the Heroku server's executable file. Place it in the root folder. This time, we will execute the Express startup file.

text
web: node app.js

.gitignore Configuration

Configure your project so that only executable files, such as bundled files, can be deployed.

jspm can be run on the server side, but since we've bundled everything this time, we've configured it not to be processed by the server.

For this reason, I created a `core` folder and copied the `system.js`-related files from `jspm_packages` into it.

I also changed the file path to `system.js` within `index.html`.

Create a `.gitignore` file to specify folders and files to be ignored by Git.

text
# ignore
/*
# not ignore
!/core
!/dist
!/routes
!/styles
!/views
!/.gitignore
!/.npmignore
!/app.js
!/config.js
!/favicon.ico
!/package.json
!/Procfile

Since there were many files to ignore, I ignored everything first and then unignored the necessary ones.

Deploying Files to Heroku

Git Initialization

Open the command prompt and navigate to the Aurelia.js folder you created.

bash
cd C:\project\aurelia-test
bash
git init

Logging in to Heroku

text
heroku login

Log in with the email and password you registered with Heroku.

Local Operation Check

text
heroku local web

Creating a Heroku Application

Create an empty application. This can be done either via the command line or from the Heroku website.

sql
heroku create myappname

Checking Git

Check if your Git remote settings are connected to your Heroku application.

bash
git remote -v
bash
heroku  https://git.heroku.com/myappname.git (fetch)
heroku  https://git.heroku.com/myappname.git (push)

If it's not connected, run the following command to set up the Git remote.

text
heroku git:remote -a myappname

Pushing Files with Git

Push the files to Heroku. This completes the deployment.

bash
git add .
git commit -m "my first commit"
git push heroku master

Commit the indexed files. The `-m` flag is used to add a comment. If you don't provide a comment with `-m`, a text editor will open, prompting you for one.

Heroku will build the application based on `package.json`.

Packages listed in `dependencies` will be installed.

You can confirm this by accessing the following URL. You can also check your app and change settings from the Heroku website.

text
https://myappname.herokuapp.com/

※ If you want to run files that are not bundled by `gulp bundle`, you will need to modify your `.gitignore` settings. The `.gitignore` file described here is for cases where only bundled files are handled.

📦
Amazon で関連書籍・ツールを検索
web development programming book
Amazonで探す →(アソシエイトリンク)