Bob
0
Q:

express public

app.use(express.static('public'))
5
app.use(express.static(__dirname + '/public'));
0
app.use(express.static('public'))
app.use(express.static('files'))
1
Static file is any content that can be delivered to an end user without 
having to be generated, modified, or processed.
1
express.static(root, [options])
0
// node js -> express -> basic example: static folder, 404 page

const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 5000;

const app = express();

function error404(req, res) {
  res.status(404);

  if (req.accepts('html')) {
    res.sendFile(path.join(__dirname, 'public/errors/404.html'));
    return;
  }

  if (req.accepts('json')) {
    res.send({
      status: 404,
      error: 'Not found'
    });
    return;
  }
  
  res.type('txt').send('404 - Not found');
}

app
  .use(express.static(path.join(__dirname, 'public')))
  .use(error404)
  .listen(PORT, () => console.log(`Listening on ${ PORT }`));
1

New to Communities?

Join the community