Recent long-term support (LTS) versions of Node.js and utilities are available.

Configuring web applications

Web applications (silkv2 only) use Phusion Passenger as an application server. This will automatically take care of starting up your code when someone tries to access it with a web browser; you will not launch it directly with node. For this to work, do the following:

  1. Make the following tweaks to your app.js file:

    1. As early as possible in your code, add the following:

      if (typeof(PhusionPassenger) !== 'undefined') {
          PhusionPassenger.configure({ autoInstall: false });
      }
      
    2. Modify your call to http.Server.listen():

      if (typeof(PhusionPassenger) !== 'undefined') {
          proxyServer.listen('passenger');
      } else {
          proxyServer.listen(3000);
      }
      

    See Reverse port binding in Node.js from the Phusion Passenger documentation for more information.

  2. Place the following in an .htaccess file in your ~/www-root/ directory:

    PassengerAppType node
    PassengerAppRoot /users/m/y/mynetid/www-root/myapp
    PassengerNodejs /opt/nodejs/v10/bin/node
    

    PassengerAppRoot should be the full path to the directory where your application's app.js is located.

    PassengerNodejs should be the path to your chosen version of Node.js.

Choosing a version of Node.js

You can choose among multiple versions of Node.js:

Node.js version Command-line path
8.x (default) /opt/nodejs/v8/bin/node
10.x /opt/nodejs/v10/bin/node

If you need to switch Node.js versions for command-line usage, you can do so by creating or editing your site's .silk.ini file (for example ~/www-root/.silk.ini) and adding the version to the [nodejs] section:

[nodejs]
version = 10

Valid version choices are default, any of the versions listed in the table above, or newest (which provides the newest available on the system). Changes will take effect when you next log in.

Choosing an application environment

By default, the application server will start your app in production mode, so that process.env.NODE_ENV == 'production'. If you want to use development or something else, add a line such as the following to your .htaccess file, and restart your application:

PassengerAppEnv development

Reloading applications

An application needs to be restarted for code changes to take effect. You can do this by killing the current application process:

[myusername@silk21 ~]$ pkill -u myusername -f NodeApp

Your application will relaunch the next time it is requested from a web browser.

Accessing console logs

Console logs are written to the server-wide log files, which are not easily accessible to general users. Several alternative options, including alternate log writers and overriding the default console log behavior, can be found in a useful Stack Overflow discussion here.

npm packages

You can install packages for your application with npm. If you need to install something "globally" rather than inside your application's directory, you can change npm's default directory to another directory.