Running Server-Side Javascript (SSJS) on Ubuntu

Automated disclaimer: This post was written more than 15 years ago and I may not have looked at it since.

Older posts may not align with who I am today and how I would think or write, and may have been written in reaction to a cultural context that no longer applies. Some of my high school or college posts are just embarrassing. However, I have left them public because I believe in keeping old web pages aliveā€”and it's interesting to see how I've changed.

Using JSEXT, I can now run javascript as a server-side scripting language on my Ubuntu box!

The main awesome thing about JSEXT is that a javascript file can be run either client- or server-side. This means that much your data validation code and some of your business logic can be kept in the same language, instead of splitting it into (for example) PHP + javascript. Furthermore, there's only one file to maintain for any given bit of logic.

Here's a quickstart guide to get JSEXT up and running with Apache 2 on Ubuntu 8.04 Hardy Heron:

Install jsext package

The package wasn't in the Ubuntu 8.04 Hardy Heron repository at the time of this writing (2008-10-25), so I downloaded the latest (v1.1) from SourceForge. You will need libffi5, which has not yet been backported to 8.04 Hardy. I downloaded it from the 8.10 Intrepid repo.

Configure Apache

The module needs to be loaded into Apache. Future versions of the package will no doubt do this automatically, but for now it's a manual process.

Write the following to /etc/apache2/mods-available/jsext-cgi.conf:

<IfModule mod_cgi.c>
  AddHandler jsx-cgi .jsx .js
  Action jsx-cgi /jsx-cgi-server
  ScriptAlias /jsx-cgi-server /usr/bin/jsext
</IfModule>

Write the following to /etc/apache2/mods-available/jsext-cgi.load:

# Depends: cgi actions

Run the following as root:

a2enmod jsext-cgi
/etc/init.d/apache2 force-reload

Test your installation

Any .jsx files on a web server will be interpreted as server-side javascript. They can include each other as well as .js files. Leaving the question mark off the URL will return source code instead of executing the program.

Write the following to /var/www/hello.jsx:

function()
{
	print('Hello world!');
}

View the page in your browser: http://localhost/hello.jsx?.

Responses: 6 so far Feed icon

  1. Gimlith says:

    Hi,

    I'm using a ubuntu 8.10 and i can't install on it. Is there some people who know where i can found the right package for "Intrepid Ibex".

    Or perhaps some one can make a checkinstall from his functional source and send the package.

    Thank's to everyone

  2. Tim McCormack says:

    Well, I've got it running on 8.10, though I installed it when running 8.04.

    It would be helpful to know what error you are encountering when trying to install the package from SourceForge.

  3. Gimlith says:

    First of all, really sorry for don't replying to you.

    My computer was down for a lot of time, and this is just today i can read your post (a lot of other things todo before retrying jsext). So please, forgive me.

    So i'm under 8.10 and when i try installing jsext_1.1-1_i386.deb, it reply than i need libiff5, then when i try to install it from libffi5_3.0.5-4_i386.deb, GDebi say i allready have this package on the system.

    I have made a tentative from source but i miss some headers files and i don't know where i can identify a download them. for now it's : checking readline/readline.h usability... no checking readline/readline.h presence... no checking for readline/readline.h... no configure: error: Missing readline

    I don't know how i can install it.

    Sincerely sorry for my first attempt.

  4. Tim McCormack says:

    @Gimlith: Those error messages mean you need the development version of the readline library. Try installing libreadline5-dev, then re-compiling.

  5. Gimlith says:

    Hi, and Thank's a lot :

    That work and i'had to install

    sudo aptitude install libreadline5-dev libffi-dev libcdb-dev libfcgi-dev libsqlite3-dev libmysqlclient-dev libghc6-haskelldb-hsql-postgresql-dev

    be carefull about this package selection because i'm not sure about that. a least for me that work.

    jsext jsext> print('hello world\n'); hello world jsext>

    Thank's Tim.

  6. Omega says:

    The only thing I didn't like about JSEXT is having to add the query string to the end of the URL...Kind of an odd last-minute kludge. Especially considering that without it, all your source is displayed :/

    JSEXT is by far the best I've seen yet though!

Self-service commenting is not yet reimplemented after the Wordpress migration, sorry! For now, you can respond by email; please indicate whether you're OK with having your response posted publicly (and if so, under what name).