Monday, August 4, 2014

Node Server.js in Raspberry Pi

To serve a page using Node.js  require a few lines of code. Raspberry pi browser shows hello world webpage which is running on Node(screenshots below)


Node Server.js program running
 



Raspberry Pi browser shows the page in localhost port 8888




Server.js Program

node.js Hello World Program

Just thought of writing a program in Node.js. There are a lot of tutorials in Node.js.

I am following the link http://www.nodebeginner.org/#javascript-and-nodejs

HelloWord program

use console.log for printing strings.

console.log("Hello World");


Node.js on Raspberry Pi

I am not sure much about Node.js. But like to try something with node.js in Raspberry pi. Here is installation steps for Node.js.

Node.js is a cross-platform runtime environment and a library for running applications written in JavaScript outside the browser (for example, on the server).

Node.js applications are designed to maximize throughput and efficiency, using non-blocking I/O and asynchronous events. Node.js applications run single-threaded, although Node.js uses multiple threads for file and network events.Internally, it uses the Google V8 JavaScript engine to execute code, and a large percentage of the basic modules are written in JavaScript.

Node.js was created by Ryan Dahl starting in 2009. Its development and maintenance is sponsored by Joyent.

Installation Steps for Node.js in Raspberry Pi


1. sudo apt-get upgrade
2. sudo apt-get update

Install Node and NPM

wget http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-arm-pi.tar.gz
tar -xvzf node-v0.10.2-linux-arm-pi.tar.gz


set the path variable as the bin directory

PATH=$PATH:/home/pi/node-v0.10.2-linux-arm-pi/bin

after the setting the path variable , try the command in command line
npm  - -version

in order to work on native modules , we need to install  node-gyp

check whether gcc is installed or not ?
gcc --version

install Native

npm install -g node-gyp