Node.js on OSX

Node.js is an open source, cross-platform runtime environment for server-side and networking applications. Node.js applications are written in JavaScript, If you are not already familiar with what Node.js is, you can learn more over it from here.

We will be using Homebrew to install Node.js, Homebrew makes it more easier to install and upgrade Node.js.

Getting Started

Downloading and installing Homebrew (XCode need to be installed)

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

You can install Node.js by entering this command.

brew install node

To check everything is working correctly you can run.

brew doctor

Now you have Node.js installed on your Mac

Sitemap for Wintersmith

Sitemap helps Search Engine index your website. It give the search engine a list of all the links available.

If you don’t have a sitemap your website might not be indexed correctly and only some links will be shown in search result. Wintersmith is a really good static site generator. I have written a template for it that generates the sitemap.xml file so search engines can index your website. All you need to do is to clone this github repo and copy the sitemap.json from the contents directory and places it into your website source contents directory. Next copy the sitemap.jade from templates directory and place it in your website source templates directory. This will automatically generate the sitemap required for your website.

Node.js installation for Raspberry Pi…

Node.js is a brilliant platform for creating network applications. It is mainly known for its non-blocking I/O and event driven system. In simple terms, Node.js can easily handle a large number of requests while simultaneously consuming lesser server memory. These are the attributes one should be looking for in a low power server like, you guessed it, Raspberry Pi. Here, you’ll learn how to setup Node.js for Raspberry Pi.

Node.js

ON

Raspberry Pi

Why use Node.js?

Node.js comes with a built in HTTP server library. This means it doesn’t require the help of any external piece of software to act as a web-server. Using Node.js alone one can have greater control of the web-server parameters.

Of course, all we care about it tinkering. Cool new web applications require Node.js to function and we like our Raspberry Pi not being a source of heat all the time. Of course, you could check the Wikipedia entry as well as their very own site.

Installing Node.js on Raspberry Pi

1. Download the Node.js package for ARM

As you must be aware, the Raspberry Pi sports an ARM11 chip. So, the package optimised for ARM will have to be downloaded. It can be done by entering the following command into the terminal.

wget http://node-arm.herokuapp.com/node_latest_armhf.deb

2. Install the package

Once the download is complete, it needs to be installed and can be done using the following command.

sudo dpkg -i node_latest_armhf.deb

And that’s it! Quick, wasn’t it?

By its end, we will have NodeJS and NPM (Node Package Manager) installed on your Raspberry Pi.

Testing the installation

The process is pretty foolproof but it wouldn’t hurt to test the installation with a simple server script.

1. Write the server script

Below, we have written a script that displays “Hello World!” to the client.

var http = require('http');
http.createServer(function (request,response) {
 response.writeHead(200, {'Content-Type': 'text/plain'});
 response.end('Hello World!\n');
}).listen(8000)
console.log("Web Server running at http://127.0.0.1:8000")

Update: There’s a chance the code might not appear in with proper line-breaks on your PC. So, here below we’ve enlisted the above code in its right syntax:

 

#### Save the script in a file

Save the script in a .js javascript file. Something like greetings.js would be a good idea if you’re not feeling particularly creative.

2. Run the script

Use the node program from the command line to execute the server. Something like so.

node greetings.js

You’ll receive an output like this.

Hello World!

If you’d like you could visit http://127.0.0.1:8000 and be greeted “Hello World!”.

And that is that!

Stay tuned for more on Raspberry Pi, Node.js and all of the web-apps based on it. Do leave us comments if you’d like us to do anything for you…