Simplest node express static files server

The simplest node static files server.

Create the project and install express package

npm init
npm install express --save

Create server.js file in the root.

// server.js
const express = require('express');
const app = express();


/* routes root '/' to index.html */
app.get('/', (req, res) => {

app.listen(3000, () => console.log('Listening on port 3000..'));

Create a static page

Now all files in www folder are being served. Create a www folder in the root and add an html file.

<!DOCTYPE html>
<html lang="en">
    <title>Static express</title>
        <p>All work and no play makes Jack a dull boy.</p>

Run it locally

node ./server.js

Open a browser at localhost:3000.

Now docker, of course.

Create a Dockerfile

# Dockerfile
FROM node
WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .
CMD ["node", "server.js"]

And a .dockerignore


Run it

docker build -t express-static-server .
docker run -p 3000:3000 express-static-server

Open a browser at localhost:3000.