Reputation: 75656
I want to make express serve files requested as http://localhost/uploads/image.png
serve the files out of a dynamic directory (based on environment) process.env.NODE_UPLOAD_DIR
which would be something like:
/home/user/data/uploads
but the app is served out of ~/www/domain.com
.
Is this possible?
I tried this, but it just redirects to homepage in browser when I request it (its an angular app if that makes any difference):
app.use(express.static(path.join(proces.env.NODE_UPLOAD_DIR, 'uploads')));
Upvotes: 0
Views: 105
Reputation: 145994
If you want the "uploads" portion in both the URI and the filesystem path, you need to use it as a prefix:
app.use('/uploads', express.static(
path.join(process.env.NODE_UPLOAD_DIR, 'uploads'))
);
Upvotes: 1