Express.js Pass-Through Directory
Support this website by purchasing prints of my photographs! Check them out here.DEPRECATED: This post may no longer be relevant or contain industry best-practices.
Would you like to server up a directory of static content using express.js? Then look no further. This URL will match all requests for the top level assets directory, and will server up a file from the local assets directory relative to where the script was executed from. You can independently change the name of the folder on disk and the URL without interfering with each other.
app.get('/assets/*', function (req, res) {
res.sendfile(__dirname + '/assets/' + req.params[0]);
});
Unfortunately, I have no idea if this is secure, or if it is a best practice. Please leave feedback if you have any better suggestions.