There is a mayor challenge when developing code for etherpad. While it is easy to see what happens on client side using FireBug, there’s nothing comparable for server-side code. That’s a big problem if you want to learn how etherpad works on server-side. Sure, you can read the sources, but without viewing a specific function call in action and examining what variable has what value, this is not very comfortable.
A few days ago, there was a mail on etherpad-dev, telling that there’s a new project growing up named etherpad-lite, which uses node.js instead off AppJet for server-side JavaScript. In addition, they mentioned, that they were able to take 98% of the existing code with just minor adjustments. Now so what, they use node.js, not AppJet, where’s the deal ?
There are options to debug (server-side) node.js code. This fact in conjunction with the statement, that etherpads server-side code used in etherpad-lite is almost the same as in stock Etherpad leads to a simple idea. Debugging etherpad-lite will give you most of the information you need to understand how stock etherpad works on server-side.
The development environment
In this section I will tell you, how to create an appropriate development environment to debug etherpad-lite server-side JavaScript code. The following explanations assume, that you have Ubuntu 10.04 installed. First, you have to install some required software packages.
- apt-get install libssl-dev*
- apt-get install g++
- apt-get install curl
- apt-get install libsqlite3-dev gzip git-core
Now it’s time to build node.js. The etherpad-lite site states, that the current development snapshot works with node.js 0.4.x, so we will grab exactly this release (and not 0.5.x). In order to build node.js you can create a directory named github in your home directory and clone the 0.4 release of node.js to this location.
- mkdir ~/github
- cd ~/github
- mkdir joyent
- cd joyent
- git clone –depth 1 git://github.com/joyent/node.git
- cd node
- git checkout origin/v0.4
Node.js has to be built and installed. In order to do so, just create a directory for node.js in your home directory. Afterwads, do configure, make, make install.
- mkdir ~/local
- ./configure –prefix=$HOME/local/node
- make
- make install
Of course, no program will find node.js in that uncommon location, so you have to add the following lines to your ~/.profile.
- echo ‘export PATH=$HOME/local/node/bin:$PATH’ >> ~/.profile
- echo ‘export NODE_PATH=$HOME/local/node:$HOME/local/node/lib/node_modules’ >> ~/.profile
- source ~/.profile
Now you are able to grab etherpad-lite. Therefor, create a directory below ~/github to store the cloned pad from github.
- mkdir ~/github/Pita
- cd ~/github/Pita
- git clone git://github.com/Pita/etherpad-lite.git
- cd etherpad-lite
In order to finish the etherpad-lite setup and to install the web-based node.js debugger later on, install the Node Package Manager (npm).
- curl http://npmjs.org/install.sh | sh
- cd ~/github/Pita/etherpad-lite
- npm install
- bin/run.sh (the debug run script does not fetch jquery at the first start …)
- Abort etherpad-lite using CTRL-C
It’s time to install the node-inspectore, the web frontend to node.js debugger.
- npm -g install node-inspector
- cd ~/github/Pita/etherpad-lite
- bin/runDebug.sh (or bin/debugRun.sh, depending on your version of etherpad-lite)
The node-inspectore web-based node.js debugger front-end will now accept connections on port 8080, BUT YOU HAVE TO USE GOOGLE CHROME. Other browsers will not work. You can try it, if you want. Now click on “Scripts” and you will see server-side JavaScript code. Using node-inspector is beyond the scope of this post. The following video will give you a short introduction.
[…] has written a superb blog post on how to debug Etherpad Lite. If you do need to debug Etherpad, Etherpad lite might be your best option as it has a more simple, […]
Thanks Michael, I linked to this on The Etherpad Foundation blog
I will rename bin/runDebug.sh to bin/debugRun.sh, thats just to let tab auto complete work better
[…] https://somethingaboutcode.wordpress.com/2011/07/26/debug-etherpad-lite-server-side-javascript/ […]