Node express change static folder on a user by user basis Node express change static folder on a user by user basis express express

Node express change static folder on a user by user basis


Think I have a solution for you!

app.get('/:user', function(req, res, next) {    app.use('/', express.static(path.join(__dirname, 'public/' + req.params.user)));    res.send('');});

To explain, imagine the two files at the paths:

/__dirname/public/user1/userdata.text

/__dirname/public/user2/userdata.text

By visiting the following two URLs:

http://localhost:3000/user1/userdata.txt

http://localhost:3000/user2/userdata.txt

You'd be requesting those two different files respectively. If the file doesn't exist, it throws a 404 like you'd expect!

Hope this helps.