Archive

Archive for the ‘node.js’ Category

Yet another must have node.js module – underscore-cli

September 12, 2012 Leave a comment

If you love underscore.js and happen to be a CLI nut, you should not miss out underscore-cli, see

https://npmjs.org/package/underscore-cli

for details, or simply install via (assuming you are already using node.js)

sudo npm install -g underscore-cli

Test Drive:
curl https://api.github.com/users/midnightcodr|underscore print --color

Categories: javascript, node.js

Install node.js on Raspberry PI in two simple steps

July 24, 2012 13 comments

[ Updated Jan 20, 2013 ] Check out my git repository https://github.com/midnightcodr/rpi_node_install if you are interested in putting newer version of node to raspberry pi (tested with 0.8.14, os runs raspbian)

1) Install the newest wheezy image onto the sd card (currently 2012-07-15-wheezy-raspbian.zip) from http://www.raspberrypi.org/downloads

2)

sudo apt-get install nodejs npm

, press y, Enter when prompted, you will get node.js (v0.6.19) and npm (1.1.4) installed in a few minutes, which should be the easiest way to get node.js and npm up and running on RP.

Note: If you want newer version of node.js you might want to check this out: http://www.raspberrypi.org/phpBB3//viewtopic.php?f=34&t=9929, I have tested the method described in this post in the previous release of wheezy (http://www.raspberrypi.org/archives/1435) and I assume it should work with the current image as well.

Categories: node.js, raspberry pi

A simple password generator written in node.js

Probably not a very advanced password generator but should be adequate for general purpose, see https://github.com/midnightcodr/gen_pass for details.

Sheevaplug + Debian 6 (Squeez) + node.js 0.6.13

March 21, 2012 Leave a comment

1) Preparation

apt-get install build-essential libssl-dev curl
cd /tmp
wget http://nodejs.org/dist/v0.6.13/node-v0.6.13.tar.gz
tar xzf node-v0.6.13.tar.gz
cd node-v0.6.13

2) Edit file deps/v8/SConstruct as follows:

//line #80
  'gcc': {
    'all': {
      'CCFLAGS':      ['$DIALECTFLAGS', '$WARNINGFLAGS', '-march=armv5t', '-mfloat-abi=soft'],
      'CXXFLAGS':     ['-fno-rtti', '-fno-exceptions'],
    },


//line #1081
  'armeabi': {
    'values': ['hard', 'softfp', 'soft'],
    'default': 'soft',
    'help': 'generate calling conventiont according to selected ARM EABI variant'
  },

3) Compile & Install

./configure
make && make install

Step 3) will take about 40 minutes. If installation is successful, command node -v should print v0.6.13.

4) Download and install npm

curl http://npmjs.org/install.sh | sh
npm list -g
ln -s /usr/local/lib/node_modules ~/.node_modules

The ln command is optional but it’ll make require statements much easier.

Categories: Debian, node.js, sheevaplug

Example: sorted set functions with node.js + redis

February 28, 2012 1 comment

Have been playing with node.js module redis (and a bit of underscore) almost all day and I could not find any examples using zrange (or zrevrange) so I decided to write one as a practice:

var rc=require('redis').createClient();
var _=require('underscore');

rc.zincrby('myset', 1, 'usera');
rc.zincrby('myset', 5, 'userb');
rc.zincrby('myset', 3, 'userc');
rc.zrevrange('myset', 0, -1, 'withscores', function(err, members) {
        // the resulting members would be something like
        // ['userb', '5', 'userc', '3', 'usera', '1']
        // use the following trick to convert to
        // [ [ 'userb', '5' ], [ 'userc', '3' ], [ 'usera', '1' ] ]
        // learned the trick from
        // http://stackoverflow.com/questions/8566667/split-javascript-array-in-chunks-using-underscore-js
	var lists=_.groupBy(members, function(a,b) {
		return Math.floor(b/2);
	});
	console.log( _.toArray(lists) );
});
rc.quit();

Have fun.

Categories: node.js, redis, underscore

System load monitoring with nodejs+socket.io+flot

February 12, 2012 Leave a comment

I am a big fan of node.js, socket.io and a long list of other node modules, as you might have known through my News Board app. While working on a html5 charting project a few years back I discovered flot which I also became a fan of. I started a few weeks ago working on a real-time charting app with the technologies I just mentioned, by plotting some randomly generated numbers (streamed through socket.io) with flot. Today I just changed the app by using real data – system average loads. Check out the project at github if you are interested in. My next goal is to use Redis to handle the data captured.[update] A new branch using Redis as data store has also been implemented.

Screenshot:

Categories: flot, node.js, socket.io

A real-time app made with node.js, socket.io, express …

January 19, 2012 2 comments

This past weekend I decided to work on a pet project – build a real-time app using node.js.

Modules used: socket.io, express, jade, sqlite3.

Still screenshot:

News Board still image

News Board 3 clients on the left, admin UI on the right

Checkout the source codes at:
https://github.com/midnightcodr/news_board

Video demo is available here (audio-less).

Have fun.

Categories: node.js, socket.io
Follow

Get every new post delivered to your Inbox.