Poking around

It's my understanding that Apps go to sleep when not in use
and take a second or two to "Wake up". But,
if you have more than one server it will remain awake all the time and
be very responsive. (Don't quote me on that)

Click on the app to open it.

Here is what I see.

Click this guy to open the Application.

There is my webapp

Going back to the first screen I can see the app is now
"Awake"

Click on Production Check.
There is some good info there.
Like that you need more than 1 server to have it not go to sleep.

Remove the app

… How do I remove this app so I can start clean?

Click on Settings

Scroll to the bottom and click Delete app…

Enter the apps name, which is shown on the top, click Delete
App.

It's gone

Reloading the page results with this message "No such
app"

Create a Basic Express App

I am going to create a very basic Express app using TDD
(Test Driven Development), save it to a
git repo and push it to a git server I have.
Then I am going to figure out how to push it up and run it on Heroku.

Create a new folder and run npm to initialize it.

> mkdir MyApp

> cd MyApp

> npm init

After all that I should have a package.json. Here is mine.

{

"name":
"MyApp",

"version": "1.0.0",

"description": "",

"main":
"app.js",

"scripts": {

"test": "mocha --recursive test"

},

"author":
"Patrick Bailey",

"license": "ISC"

}

Edit the package.json file

> vi
package.json

Add the following

{

"name": "MyApp",

"version": "1.0.0",

"description": "",

"main": "app.js",

"private": "true",

"scripts": {

"test": "mocha --recursive
test"

},

"author": "Patrick
Bailey",

"license": "ISC"

}

I am going to make this a private module (So it can't
accidentally get published to npm).

Install mocha and chai

I am going to use mocha and chai for TDD (Test Driven
Development). I am still getting used to
Node and npm so I may do this next part wrong, but I am trying my best to get
it right.

If I run

> npm install
mocha

It creates the node_modules folder, if it does not exists,
and downloads the mocha libraries and its dependencies. But it does not update the package.json
file.

Since it's not in the package.json, as a dependency, when
someone else gets my app and they run "npm install" they won't get this
module downloaded.

I could install it
globally

> npm install
-g mocha

Then I can run it from the command line. Of course I would then need to make sure
whoever runs my test script also has it installed globally.

I could install it locally and save it to the package.json

> npm install
-S mocha

That installs it in node_modules and updates package.json
with mocha as s dependency.

Saving the module does not seem the way to go for a module solely used for testing. Mocha and chai are modules I don't want to
deploy to production. What do I
do?

Looks like I need to add the "engines" field to
package.json, to tell Heroku which version of node to use.

> vi package.json

Here is my updated package.json

{

"name":
"MyApp",

"version":
"1.0.0",

"description":
"",

"main":
"app.js",

"private": "true",

"scripts": {

"test":
"mocha --recursive test"

},

"engines" : {

"node" : "0.12.x"

},

"author":
"Patrick Bailey",

"license":
"ISC",

"dependencies": {

"express":
"^4.12.3"

},

"devDependencies": {

"chai":
"^2.2.0",

"chai2-json-schema":
"^1.2.0",

"mocha":
"^2.2.4",

"superagent": "^1.1.0"

}

}

Add it to the git repo
and push it up

> git status

> git add --all

> git commit -m
"Added engines to application.json"

> git push

Try to run it locally using Heroku's foreman app

> foreman start

Ooops I need a Procfile!
…. Oh wait I don't need one??

From Heroku

Specifying a start script

If you define scripts.start in your
package.json file, you don’t need to manually create a Procfile because it will
be created automatically. For more information, see Best Practices for Node.js
Development: Specify a start script and Heroku Node.js Support.

I do have a "default" start script in package.json…
Maybe foreman needs this to be explicit?

I updated my package.json to the following.

{

"name":
"MyApp",

"version":
"1.0.0",

"description":
"",

"main":
"app.js",

"private":
"true",

"scripts": {

"test":
"mocha --recursive test",

"start": "node
server.js"

},

"engines" : {

"node" :
"0.12.x"

},

"author":
"Patrick Bailey",

"license":
"ISC",

"dependencies": {

"express":
"^4.12.3"

},

"devDependencies": {

"chai":
"^2.2.0",

"chai2-json-schema": "^1.2.0",

"mocha":
"^2.2.4",

"superagent": "^1.1.0"

}

}

Now use forman to run it.

> foreman start

Same result…

Maybe it needs the Procfile locally to run foreman. But it does not need it to run when you push
it up to Heroku?

Let me try that.

> vi Procfile

And place the following in it.

web: node server.js

Now use forman to run it.

> foreman start

Now it works

And the web app works locally.

If I don't want this file added to my git repo I need to add
it to the .gitignore file.