express sendfile root path

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

app.get('/file/:fileName', (req, res) => {
  const fileName = req.params.fileName;
  const filePath = __dirname + '/path/to/files/' + fileName;

  res.sendFile(filePath);
});

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

This code sets up an Express server that listens for GET requests on the '/file/:fileName' endpoint. When a request is made, it extracts the file name parameter from the URL and constructs a file path based on the root directory (__dirname) and the provided file name. Finally, it sends the file located at the specified path back to the client as a response using res.sendFile().