2808 explained code solutions for 75 technologies


nodejsStatic file server with Node.js and Express


const express = require('express');
const path = require('path');

const app = express();
const port = 3000;

app.use(express.static('/var/www/files'));

app.get('/', (req, res) => {
  res.sendFile('/var/www/files/index.html');
});

app.listen(port);ctrl + c
app = express()

create Express app

express.static

server static files from given directory

/var/www/files

path to static files root directory

app.listen

launch app on specified port