How to get a mongo/node instance up and running so that you can play with it.
Get a Heroku account
Do this tutorial up until the 'Provision a database' step
except in Prepare the app when it asks you to clone the repo, clone this repo instead.
The following steps are from here:
add a new database:
$ heroku addons:create mongolab
Then find it's connection uri:
$ heroku config | grep MONGODB_URI
At the bottom of your
index.js change this line to be yout URI (i.e. not mine):
// Connect to Mongo on start var mongoURL = 'mongodb://heroku_d58bh1wm:email@example.com:63899/heroku_d58bh1wm'; // <-- but put in YOUR one from the step above
Then git commit and
git push heroku master
Your app should be working now!
A route is the bit after the first
/ that tells the app what page to go to, or in our case, what do do with the data we're going to flick at it.
index.js There are two useful routes. I've used URL params to make it easier to test.
The first is
/in-url-params which takes two params
base. What these words are isn't really important. Just think of them as some things that you are sending to the server. It could be anything eventualy. You'd use this like this:
The second is
/out-url-params-base which lists all the entrys for a particular base.
This assumes a really simple model where the data gets thrown at the server by the RPi, the server saves it and then later on you'd query the data.
In reality the saving would be made safer, and the query would be much more interesting, but it's a start.
A barebones Node.js app using Express 4.
This application supports the Getting Started with Node on Heroku article - check it out.
$ git clone firstname.lastname@example.org:heroku/node-js-getting-started.git ## or clone your own fork $ cd node-js-getting-started $ npm install $ npm start
Your app should now be running on localhost:5000.
Deploying to Heroku
$ heroku create $ git push heroku master $ heroku open
For more information about using Node.js on Heroku, see these Dev Center articles: