node.js support

24 Jul 2021

The latest update brings Node.js support. This will allow you to deploy a node.js app to one of your sites, like so:

Prerequisites

In order for this to work you will need to have certain packages installed on your server. New servers deployed as of this writing will have these packages already installed but if you've set up a server previously you will need to run the following commands in terminal:

# sudo apt-get -y install nodejs npm
# sudo npm install -g pm2
# sudo a2enmod proxy
# sudo a2enmod proxy_http
# sudo apachectl restart

Setting up a node.js site

Create a new site in ServerWand and clone a Git repository from the Apps tab.

You can do this by clicking Git Repository, entering a Git URL and pressing save.

We're using the sample app: https://github.com/johnpapa/node-hello.git

Note that the repository requires a package.json file in order for ServerWand to recognise it as an app.

Once Saved, ServerWand will clone the repository, automagically install the dependencies and set up an HTTP proxy.

In order for the proxy to work, the app should make use of the PORT environment variable e.g:

const port = process.env.PORT || 3000;

The apps screen will then show the app details and provide a switch to toggle the app on and off.

Once started you can open the website in your browser and view your first node.js app

Any static files in the public folder will continue to be served as normal and SSL can be enabled in the usual way.

You can see all running apps on the server by browsing to the new Apps tab in the Server section.

If you have any questions, catch us on the discord using the footer link below.