Setting up node.js and MongoDB on a Raspberry Pi

I wanted to get node.js and mongoDB up and running on my pi.  I’ve got a couple of pet projects which I’m going to tackle and I’ve decided to use the MEAN stack (MongoDB, Express, AngularJS and Node.js).  The future, for now, is JavaScript and I’m looking to know enough to make informed decisions about my place in that future.

These are the steps that I followed to get it going …

First up, node.js …

Credit to: http://blog.rueedlinger.ch/2013/03/raspberry-pi-and-nodejs-basic-setup/

Before doing this step you want to check what the latest version is – go to http://nodejs.org/dist/ and browse, starting from the biggest number backwards, looking for a release that includes “linux-arm-pi” in the title.  That’s the one to use in the following code snippet, for me it was v0.10.24/node-v0.10.24-linux-arm-pi.tar.gz

add the following before “export PATH

That’s it!  Next let’s get a server running so we can make sure it’s working … create the following content in a file called nodejs.sh

then do the following to get it to run on pi boot

now for the server.js that will run our server

put the following in the server.js file

then start the server

A quick visit to http://192.168.0.123:8080 should result in a nice “Hello World” message.

Finally a bit of tidying up in /home/pi/

Next up – mongoDB

Credit to: https://github.com/RickP/mongopi and http://ni-c.github.io/heimcontrol.js/get-started.html

Note, the scons commands performs the build and will take a few hours each

add this before “export PATH

Then set up a new db and configure it to start on boot:

You can test everything went ok by launching the MongoDB shell with the command “mongo” … see the docs for more info.

Job Done!

Leave a Reply

Your email address will not be published. Required fields are marked *