Creating a simple file server

We will first create a simple file server to serve the front-end of our application. To do this we will make use of the Express JS Framework. Express is a (self-described) fast, unopinionated, minimalist web framework for Node.js.

Begin by opening server.js and adding the require statement for express right below the existing require statement for the paths:

const paths = require("./paths");

// Add Tutorial Code Here
const express = require('express');

Next, we will add code to serve the static files contained in the tutorial:

// create file server to serve static files
express.static.mime.types["wasm"] = "application/wasm";
const fileServer = express();
fileServer.use(express.static('public'))
fileServer.listen(8081);

As of the time of this writing, the first line of code is necessary to address an issue in Express with serving Web Assembly files. The rest configures the express server to use the public directory as a root directory for serving static files on port 8081.

We can test the file server is working correctly by running the following command in the terminal:

npm start

After running the command navigate to http://localhost:8081 in your browser of choice. You should see a page with a button and a dropdown menu, which will eventually be used for spawning viewers.