everything and nothing

allskonar

Helma, server-side Javascript

November 8th, 2007

When you’re on a Ruby on Rails binge, it’s healthy to sober up every once in a while and checkout other things. Not necessarily because you want to re-saddle somewhere else rather to get a chance to learn new tricks and get fresh ideas. I’ve been been playing with Helma the javascript server-side project that was featured in the November issue of Linux Magazine.

The Helma server is build on the rhino javascript interpreter and the java based jetty server. Which means that it’s possible to use java libraries by placing .jar files into the lib/ext directory on the server, and it will automatically get added to the classpath. For example if you need a JDBC driver for MySQL you just get the jar file for Connector/J which is the official JDBC driver for MySQL, and place it in the lib/ext and configure it.

File: db.properties


myDataSource.url      = jdbc:mysql://localhost/blog
myDataSource.driver   = org.gjt.mm.mysql.Driver
myDataSource.user     = user
myDataSource.password = password

There is an obvious benefit by having the client-side code in a interpretive language like javascript, Ruby or any of the others out there, it gives the developer the flexibility of writing code rapidly. There is also a benefit of having it sit on java especially if you need to boost performance or accomplish something that javascript cannot handle. Using javascript on the server-side, presents an interesting opportunity in sharing code base both on the client-side and the server-side, which could, if done right, prove to be a powerful concept.

Using the same language on both the server-side and client-side should help with keeping the applications code base dry. It’s easy to imagine being able to slip a javascript functions or modules through a xhr request at runtime similarly to how ruby on rails delivers the output of rjs templates or simply host the javascript modules you want shared in a place where both the server and client can reference them.

There is a downside as well, you can’t perform all tasks you might want on the server with javascript. Which means any utility scripting such as those that either needs access to the filesystem or for any other things that javascript is unable to do requires using Java or dynamic language such as Perl, Ruby, Python or bash scripts. But if there is a real possibility to sensibly share code on the server and client-side, that seems trivial.

I have been cobbled together some helma code in preparation for an actual tutorial. Where the objective is to develop a little application and explore how sharing of javascript between server and client can be accomplished. To do this I have written a very simple blog post engine where one can enter a posts, comment on posts anonymously. If you practice vigorously you can probably pretend you can code the blog application in a 15 minutes

Keep in mind that this is just a rough draft.

Leave a Reply

 
allskonar Powered by Mephisto