Our announce­ment about sup­port­ing new lan­guages gen­er­at­ed enthu­si­asm, and sev­er­al cus­tomers are already run­ning Node.js appli­ca­tions. We’re there­fore keep­ing our momen­tum up in this post, which focus­es, as you might expect, on Node.js.

A major language

As promised last week, we have a sur­prise: Node.js is becom­ing the fourth major lan­guage that always­da­ta will be sup­port­ing, after PHP, Python, and Ruby. What does this mean?

In a cer­tain way, you could say that always­da­ta has sup­port­ed Node.js for­ev­er: “all” you had to do was to down­load the inter­preter from the offi­cial web­site into your account to make Node.js run. On the web side, though, you had to play it clever in order to run the appli­ca­tion, for exam­ple by using PHP in reverse proxy. Doable… but com­pli­cat­ed.

That it’s becom­ing a major lan­guage implies:

  • that we’ve pre – installed the inter­preter, and that it is even pos­si­ble to choose from among sev­er­al ver­sions of the inter­preter (via the Environment menu in alwaysdata’s admin­is­tra­tion). Today, Node.js is avail­able in ver­sions 6.x (6.11.2) and 8.x (8.4.0)
  • that new ver­sions of the inter­preter will be reg­u­lar­ly installed, not just secu­ri­ty updates
  • that it will be easy to launch a web appli­ca­tion in this lan­guage
  • that it will be easy to install exter­nal depen­den­cies, by using the offi­cial pack­age man­ag­er in SSH. For Node.js, that’s npm, which is also pre-installed

We’ve thus added a new type of web­site, Node.js. It’s sim­i­lar to the User pro­gram type – since Node.js appli­ca­tions inte­grate their own HTTP serv­er and don’t require an inter­me­di­ary lay­er – with one main dif­fer­ence: it’s pos­si­ble to spec­i­fy an explic­it ver­sion of Node.js for this site. And there­fore to have sev­er­al dis­tinct web­sites using dif­fer­ent ver­sions of Node.js.

Example: deploying an Express application

Express is one of the best-known Node.js frame­works. Let’s see how to host an appli­ca­tion devel­oped using it.

  • First off, we have to install Express. Follow the offi­cial doc­u­men­ta­tion, exe­cut­ing the com­mands in SSH (and accept­ing every­thing by default):

  • Then, let’s cre­ate the app.js file, all the while con­tin­u­ing to fol­low Express’s doc­u­men­ta­tion. Modify the code slight­ly so that the appli­ca­tion is lis­ten­ing on the IP and port that will be pro­vid­ed as envi­ron­ment vari­ables:

  • Finally, from with­in alwaysdata’s admin­is­tra­tion, let’s cre­ate a Node.js type site, insert­ing the fol­low­ing com­mand:

There you have it: our lit­tle Express appli­ca­tion can indeed be reached!

Next lan­guage com­ing up, for the sec­ond post in our series: Lua.