Node.Js example of exposing a file for download from a server

Using node js you can allow a user to download a file from a server. This is not complex to do, however, it will allow any user to download the file. Example of node js download file from server: module.exports.Downloader = () => { const fs = require('fs') const downloadFileDBLocal = (req, res) => { const file = 'db.json' res.setHeader('Content-disposition', 'attachment; filename=' + 'db.json') res.setHeader('Content-type', 'application/json') const filestream = fs.createReadStream(file) filestream.pipe(res) } return { downloadFileDBLocal: downloadFileDBLocal } }