Culture / Technology / Tutorials /

Getting Started With Node.js on the Hummingboard, a Raspberry Pi Clone

22 Feb 2015 10:15am, by

Javascript’s event-driven model of execution lends itself well to server-side Internet of Things applications, particularly on nanoLinux devices, like the Raspberry Pi or a Hummingboard clone. I have a couple of Hummingboards and they are robust little devices. Since I’m just putting my toe in the Javascript water, the first order of business is that of installation and a quick check to see if I can put something up on a Web page. In a subsequent article I might expand the exploration into more complex Web examples and maybe try some input/output on the GPIO pins of the board.

Installation

Installation is fairly straightforward using the command line. I used a Hummingboard-i2eX with the i.MX6 Dual (2 core) processor, 1 GB of 64-bit 1066 Mbps memory and Debian Linux version 3.0.35. The setup also has a powered 4 port hub, a Logitech wireless keyboard/mousepad and an EdiMax 802.11n USB wireless dongle. Video is handled through the standard HDMI cable out to a Sanyo big screen. Raspberry Pis and their clones all seem pretty sensitive to power requirements, so a powered hub is pretty much a necessity. Use a 5-volt 2 amp wall wart for the Pi and Hummingboard, with a good USB cable, to head off problems.

I followed the directions on the justplugin Web site to load node.js on my Hummingboard device. Here are the steps with a bit of commentary:

1. Make a new directory to hold the downloaded nodejs files.

cd ~

mkdir nodejs_download

cd nodejs_download

2. Fetch node.js from the Internet.

wget http://nodejs.org/dist/v0.11.7/node-v0.11.7.tar.gz

tar -xzf node-v0.11.7.tar.gz

3. Compile and build the node.js programs.

cd node-v0.11.7

./configure

make

Even with the dual-core Hummingboard, a fairly fast Internet connection and 1 GB of memory compiling and building the programs, it took about 40 minutes.

4. Install the program on the Hummingboard system.

su

make install

5. Reboot the Hummingboard.

sudo shutdown -r now

6. Determine the version of node.js and the module installation programs. These commands also verify that everything is working.

node -v

npm -v

An Exceedingly Simple Example

The Web has tons of examples on how you can get started using node.js with a Raspberry Pi-based machine. I found a little program that simply posts “hello world” to a browser screen using the node.js server. Check the howtonode Web site for complete details and a handful of additional script examples.

1. Here’s the hello-node script from the howtonode site.

// ******************************************

// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

// ******************************************

2. Put the text in a file and call it hello-node.js, using your favorite command line editor.

3. Start the server and run the script with the following command line:

node hello-node.js

You’ll get a message that says the server is running on the localhost (127.0.0.1:8000).

4. Punch that IP into your Pi’s browser and the “hello world” message should appear at the top of the screen. You can also see the page from other machines, on the same network by using the IP of Hummingboard. Find it with ifconfig.

In my case, I could see the message from my XFCE Linux Asus notebook when I pointed to the 192.168.1.111:8000 (address of the Hummingboard, on my LAN), in the Chrome browser.

Conclusion

I was happy to find out that it only takes a moderate amount of effort to get node.js running on a Raspberry Pi-based nanoLinux machine. There’s a whole lot of information on the Web about Javascript and it’s a popular language. I’ll take a look at accessing the GPIO pins in a future story.

Featured image via Flickr Creative Commons.


A digest of the week’s most important stories & analyses.

View / Add Comments