Running a node js app in a subfolder on Raspberry Pi

I have a Raspberry Pi on which the htttp://raspberrypi/ URL is already taken. I wanted to run a node js app which I created and instead of having to remember an arbitrary port number I decided to run it in a subfolder instead.  Here is how I achieved it.

First I had to enable a couple of Apache modules by executing the following commands

sudo a2enmod proxy
sudo a2enmod proxy_http

Then I had to add a few more lines to my site configuration which for me is located at /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
...
# Run rpi-measurements-web-dashboard from its own subfolder
<Location "/measurements">
ProxyPass http://localhost:8080/measurements
</Location>
</VirtualHost>

For the modifications to take place I re-started Apache with

sudo service apache2 restart

Last I had to add the following route to my node app to make it work

const express = require("express");

const app = express();

app.get("/measurements", (req, res) => {
res.send('hello world');
});

app.listen(8080, () => {
console.log("Server is running on port 8080.");
});

So now if I browse to htttp://raspberrypi/measurements from my laptop I get to see “Hello world”.