Replicating a Camel/Node.js setup from Heroku onto my Raspberry Pi was really simple. Far simpler than I expected!
In the previous post I talked about setting up a website using Heroku, Node and Camel. This is working really well so far, but every change needs to be pushed live using Git. Which has a few great points, but one bad one: when editing or playing with the site, I spend more time pushing things live than I do actually coding or writing. For this reason, I decided to build a local copy of the site that I can use for development, then sync it back up to the Heroku instance when I’m happy.
I decided to set this up on a Raspberry Pi, because I’m interested to see if the Pi itself can be made stable enough to eventually become the main server for this very low traffic site.
The Toolbelt is connected to your Heroku account by running
heroku login from the terminal. Then I made a new folder for Heroku stuff, with
mkdir Heroku. I switched to that folder with
cd Heroku. Then the existing Heroku Git repository is cloned with
heroku git:clone -a j-w (where “j-w” is your existing app’s name, not mine…). This copies all the files for the website onto the local machine, into a subfolder named after the Heroku instance (in this case,
j-w). So for me, the files sit in
Node uses a system of Modules to provide additional functionality. These are normally installed manually, but Heroku automatically includes all the necessary Node modules for you when you list them in a
package.json file, like this:
For the Raspberry Pi site, the packages need to be installed locally. This is done by switching to the website folder and running
npm install. This checks the above
package.json file and installs all the needed modules into a subfolder named
node_modules/, within the website folder.
These packages should not be pushed back up to Heroku.
To stop this, I made a file called
.gitignore in the website folder, which contains the line
node_modules/ - this simply tells Git to ignore the Node modules folder. Easy!
Running the site locally with
node camel.js now serves a test version of the site on the raspberry pi, which I can then push back up to Heroku when it’s ready (ish) to go live. This is done with a few commands.
Firstly, new files (that aren’t in /node_modules/) are added to the repository with this command:
git add .
Then any new or changed files are committed to the local repository with
git commit -am "Comment here so I remember what I changed"
Finally, the new or changed files are pushed to Heroku with
git push heroku master
I had a whole lot of photos and blog posts, but wasn’t doing anything interesting with the site. The site was serving as a design portfolio, a blog, a photographic portfolio, a contact form and a whole lot of other mess. It was a nightmare to navigate and it wasn’t a good representation of anything much. I was bored with it.
This new site is going to be a lot less ‘precious.’ I’m going to try things. I’m going to break things. I’m going to post things, or at least that’s what I’m telling myself. Anyway, there are better communities in which to share photos and design portfolios than on my own, isolated, site.
I’m using this as a chance to learn more about linux and node.js, with a possible end goal of running the whole site on a Raspberry Pi. I’m not sure if I will or not, but I’d like to keep the option open. In the pursuit of minimal overhead, I’m currently running Casey Liss’s open source Camel engine to run the site. It’s simple enough that I can understand most of it, and I’m looking forward to hacking it into something else. Or using as-is — so far it’s pretty good.
Because it’s free and seemed like a good service/paradigm to learn about, I’m serving this site through Heroku.