Silk Web Hosting: Node.js
ModifiedLong-term support (LTS) versions of Node.js and utilities are available. By convention, these are the even-numbered Node.js releases.
Choosing a version
You can choose among multiple versions of Node.js:
Node.js version | Command-line path | Sunset Date |
---|---|---|
18.x (default) | /opt/mise/installs/node/18/bin/node | April 30, 2025 |
20.x | /opt/mise/installs/node/20/bin/node | April 30, 2026 |
22.x | /opt/mise/installs/node/22/bin/node | April 30, 2027 |
If you need to switch Node.js versions, 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 = 22
Valid version choices are default
, any of the versions listed in the table
above, or newest
(which provides the newest available on the system).
From the command-line, changes will take effect when you next log in.
Web applications will need to be restarted.
Packages
yarn
and npm
are available for installing packages.
If you need to install something globally rather than inside your application’s directory, you can change the default global directory to a location you own.
For yarn
, edit your ~/.yarnrc.yml
file to include a line similar to:
globalFolder: "./.yarn/global"
For npm
, you can follow these directions.
Web applications
Web applications use NGINX Unit 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:
-
Edit the
.silk.ini
file in your site root. Add a section similar to the following.[app] type = nodejs uri = /* document-root = public startup-script = app.js cmdline-args = --arg1 --arg2=blah env.MYVAR = some value
The
.silk.ini
section name should be either “app” or any descriptive name you wish for your application that starts with “app: “. This could be useful if you wish to configure multiple apps.root is an optional directory under your site root containing all your application files.
uri is a pattern matching the part of a web request URL after the hostname that should match this application, usually ending in
*
. For example,/*
matches all pages, while/myapp*
matches all pages that begin with/myapp
.document-root is the directory under your app root in which static files will be located.
startup-script is the name of the script launching your application, which should have executable permissions (
chmod u+x app.js
).cmdline-args is an optional list of command-line arguments passed to the startup script.
Any line beginning with env. will set an environment variable available within your application.
-
If this is the first web application in your site, a new app server will be started for your account within a few minutes.
-
Load your application with
silk app <hostname> load
. If you have multiple sites and/or multiple apps,<hostname>
is followed by the URI path of your app, such asdev.mynetid.w3.uvm.edu/app2
. If you see an error, check the app server log for details.
Reloading applications
An application needs to be restarted for code changes to take effect. You can do this the same way you originally loaded your application:
[myusername@silk21 ~]$ silk app <hostname> load
Console logs
App server logs are available at /var/opt/nginx-unit/<mynetid>/unit.log
.