Porting AppFog command line util to Node.js

Recently i tried to explain to a fellow developer how to update our server hosted by AppFog PaaS, everything in our process is development so its not all that great (yet) and hopefully i will eventually have time to improve & automate this, but for now here it is.

  • Built the Client side app in flash builder
  • Checkout the latest stable Node.JS server app code
  • Copy the bin-output dir of client code inside the server’s dir structure
  • Use the AppFog CLI to update the ‘dev’ version
  • conform this is working ok for a couple of weeks
  • clone to ‘production’

As i said, possibly not the neatest solution, but its what we are currently doing.

Since i develop the server using the wonderful Cloud9 the awkward part of the process is uploading the bin-output to c9’s workspace so i can update using the af util. This new dev will be deploying from an OSX machine which we shall say is ‘fresh’ no OSX homebrew etc, and for now thats the way i want to keep it. Seeing as a fresh OSX Lion machine does not have a version of ruby high enough for AppFog CLI to run, the port to Node.js was born (yes i know they will need to install this too but whatever)

So AppFog CLI and AppFog API were both born and so far have about 24 hrs work between them. I’ve separated this mini project into two parts as hopefully the appfog-api (npm link) will allow others to build automated deployment/monitoring etc into their own apps.

So please npm install af and let me know how you get on with it. Currently this lib is at a very early stage with just the ‘get’ functions but hopefully by V1.0 i should have implemented the bare minimum of af update, af push, and af stat


Cloud9 & RasPi Pt2

Following on : After completely blowing away my SD card i created another one this time installing Node 0.8.1 with these instructions and source mint installs with no problems at all.

On-to the next problem, libxml. libxml is an npm package which i believe wraps the libxml Debian package with node bindings. There is a flag set in the build command line ‘-msse2’ which is incompatible with the ARM architecture, this is known about but not yet fixed https://github.com/ajaxorg/node-libxml/issues/7

so to counter this i think i have to try and build libxml beforehand and then run the cloud9 install scrip again.

StackEx conversation

Cloud9 & RaspberryPi

Ive long been a fan of Cloud9 IDE and with my recent purchase of a RaspberryPi what better way to start some native code development than with the IDe i already know and love.

Cloud9 started off with a heavy Node.JS bias, in fact the majority is written in node, but with ACE editor at the heart and its increasing ability to access the command line, configure ‘deplyment’ commands i figure it will make a fantastic IDE for C / C++ / Python or obviously Node.js development on the PI.

So flashed my SD card with a fresh Adafruit image to get some of the kernel module bells and whistles for later use and went about getting C9 up and running.

Step 1 : Node

This was simple enough sudo apt-get install nodejs and I’ve installed node, but seeing as this is only version 0.6.* from the repo ill need npm as well sudo apt-get install npm a hop back to the command line and bobs your fathers brother

Step 2 : Cloud9

Cloud9 have some great instructions on there github readme so off to work i go. unfortuneatly this is where the wheel start to come off…

/usr/local/bin/sm -> /usr/local/lib/node_modules/sm/bin/sm

> sm@0.1.69 postinstall /usr/local/lib/node_modules/sm
> node ./scripts/postinstall.js

npm ERR! TypeError: options.uid should be a number
npm ERR! at ChildProcess.spawn (child_process.js:429:26)
npm ERR! at Object.spawn (child_process.js:342:9)
npm ERR! at spawn (/usr/share/npm/lib/utils/exec.js:103:22)
npm ERR! at exec (/usr/share/npm/lib/utils/exec.js:40:12)
npm ERR! at Array.0 (/usr/share/npm/lib/utils/lifecycle.js:141:5)
npm ERR! at EventEmitter._tickCallback (node.js:190:39)
npm ERR! You may report this log at:
npm ERR! <http://bugs.debian.org/npm&gt;
npm ERR! or use
npm ERR! reportbug –attach /usr/share/cloud9/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.2.27+
npm ERR! command “node” “/usr/bin/npm” “install” “-g” “sm”
npm ERR! cwd /usr/share/cloud9
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.4
npm ERR! message options.uid should be a number
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /usr/share/cloud9/npm-debug.log
npm not ok

Som more google shows no real answers so i figure im going to plow on and just do a standard npm install.


More updates to come. . . .

Node Communities, How am i doing?

I’ve found over my few years of ‘learning by doing’ that one of the hardest things to get is feedback. If an application works, some would say that that’s enough, but for whatever reason i would love to get some feedback from other developers, so I’m putting this post out there and willing to listen and discuss anything that may come up.

My quote book project has gone though a recent change on the ‘Dev’ Branch of this Git hub repo. if anyone would like to take the time to have a read (its not that complex) and give me some feedback either in comments or emails, that would be awesome. My current development can also be seen in cloud9 IDE

Node.JS & express as a replacement for Apache httpserver

In my ongoing learning with Node.js i find at each turn im more and more surprised at just how much it can do for me. Recently this surprise took the form of a problem ive been having froa while now with configuring Apache for proxy and reverse proxy to multiple web apps on my local server.

Here’s the run down of the situation:

i have 4 main web-app’s running on my server for various reasons and on various ports

  • Transmission on port 9091
  • SickBeard on port 8081
  • CouchPotato on port 5000
  • sabznbd+ on port 8085
  • XBMC on port 8080
  • Ajenti on port 8000

Currently i can reach each service in turn by sticking in the port as part of the URL http://server:5000/ gets me CouchPotato for example, but this isnt the nicest of URL’s to remember so what i really want is http://server/couchpotato instead. So some quick googling later and i find out that i can configure my allready installed and running Apache httpserver to do this with proxies and reverse proxies, excilent, and it all looks relatively simple to modify a few htaccess and other such setup files.

NO SUCH LUCK i consider myself a reasonable software developer and a fairly advanced computer user, so modifying a couple of files and reading a few API docs are not beyond me, but for love nor money i cannot get this stuff to work.

Skip ahead 6 months of nasty urls

I wonder if Node can do this sor of thing, quick google later and i find node-http-proxy and a 3 minute express config file later and ive got my proxies working like a dream.

With this experience and others ive decided to uninstall Apache completely and reply on Node.JS as my sole web server for just now. Hopefully this will simplify my life dramatically.

Node.JS Find

I found out about a small Node.js server / client framework call Meteor at the weekend. After watching the video and reading a bit of the front page i was hooked and spent the rest of the day trailing round the shops with Emma reading the API docs.

First of, this looks awesome if it works half as well as displayed in the video then im sold. I can integrate bootstrap and backbone into my client side and write small webapp projects in no time. exactly what you need for minimum viable product type projects.

I have some reservations as the whole project runs on top of fibers which has been getting some stick. But maybe the sacrifice of Node.js’s great non-blocking architecture for ultimate simplicity in building is something i could get behind.

Anyway keep an eye out here as im sure ill be trying to get a small web-app up and running with the framework very soon.

Small Node script for export

I Decided that i wanted to move away from simple note which has served me well for the last few years and instead rely on a notes folder in dropbox and various platform app’s to read / write to these

Simple Note has various exporting options but one of them is not what i wanted ‘all my notes as individual text files’ so i exported them as a JSON object and set to work with Node.js


var fs = require('fs');
var notesString = fs.readFileSync('simplenote_export.json', 'utf8');
var notesArray = JSON.parse(notesString);

console.log('you have '+notesArray.length+' notes');

for (var i = notesArray.length - 1; i >= 0; i--) {

var filename = notesArray[i].content.substr(0,30)
filename = filename.replace(/(\r\n|\n|\r|\/|\\||:)/gm," ");
filename = filename.replace(/\s+/g," ");
var newNote = fs.openSync('result/'+filename+'.txt','w');
fs.writeSync(newNote, notesArray[i].content);