Web Servers
Node.JS
can be used as a web server replacement on the Pi and you can create stand alone or Single Page web applications with ease.
But just for your information, in most real world applications it is recommended to use servers like the modern nginx
, light weight lighttpd
or the chunky but fully featured apache2
! And then script node.js to complement the site.
Obviously the possibilities are endless and everything depends on what you would like to achieve.
Raspberry Pi?
The Raspberry Pi can run any of those web servers. It can also run Node without any serious complications and is really fast without any complicated tweaking.
The Raspberry Pi is very capable but best would be to turn the memory split to least graphics and most RAM. Forget about using an IDE and just do everything via SSH. If you really need some more juice then put a heat sink on the BCM chip and overclock it as you feel safe. Another option would be to use multiple Pi's as a cluster to help with load balancing. You can start digging around here about clustering.
But do you really need to use node.js?
Node.JS
was intended to be used when you start (or anticipate) to get hundreds and thousands of request that require small chunks of data to be stored to DB, cached or read back with minimal server overhead. So you drive it using JS on the client but Node.JS
is actually driven by C/C++. So what happens if you need custom module or a specific change in the base code?
In a application that serves webpages node.js does not usually outperform apache for example, on single requests. The non-blocking feature of node.js is great if you have thousands of request per second for most of the day, this is where apache would block and crash.
A real world example
Ebay - During an auction when you have a count down of the last 30
seconds. You can have several people that used to refresh the page vigorously and increasing
bids. This is where node.js shines, because today you need NOT refresh
any more. That is because the JS ajaxes to node.js very often (300ms~600ms) from all clients
and is able to provide a "real life auction" experience. Ebay does not run solely off
node.js but on very complex load balanced server farms.
To build and install Node.js on the Pi*:
Obviously there is nothing wrong with using node.js instead of others and how best to learn node if not on a neat little device like the Pi. So you can compile the code yourself like this.
$ sudo apt-get install git-core build-essential libssl-dev
$ mkdir ~/nodeDL && cd ~/nodeDL
$ git clone https://github.com/joyent/node.git
$ git checkout v0.6.15 (to checkout the most recent stable version at time of writing)
update: later versions of node (current version is v0.8.18) can be built without the special steps below
next we need to tell the compiler to use the armv6
architecture for the compilation:
$ export CCFLAGS='-march=armv6'
$ export CXXFLAGS='-march=armv6'
and then edit deps/v8/SConstruct around the line 82 mark, to add “-march=armv6”:
'all': {
'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS', '-march=armv6'],
'CXXFLAGS': ['-fno-rtti', '-fno-exceptions', '-march=armv6'],
},
Then comment out lines starting around the 157 mark, to remove the vfp3 and simulator parts. Since this is a JSON-like object, remember to remove the comma on the CPPDEFINES
line!
'armeabi:softfp' : {
'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0']
# 'vfp3:on': {
# 'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
# },
# 'simulator:none': {
# 'CCFLAGS': ['-mfloat-abi=softfp'],
# }
},
Then the usual configure, make, make install process, NB I had to manually specify the location of the OpenSSL libpath:
$ ./configure --openssl-libpath=/usr/lib/ssl
$ make (to compile node (This took 103 minutes!))
$ sudo make install
Thats it, you should now have a working Node.JS install!
$ node -v should show you the version number
$ npm -v should show you the version of the Node Package Manager
* References and original article
But as pointed out in other answers you can simply download the a pre compiled binary that will just work.
Conclusions
A good piece of Pi isn't bad. You can run just about anything on the Pi- Just don't expect production level performance.