Search code examples
node.jsexpressamazon-s3passport.jsweb-frameworks

Node application and file storage


Here is my Issue:

I have a Node web application that is responsible for user authentication. Once the user has successfully logged in they are presented with a personalised page which contains secure links to files. Here is my file structure.

File Structure

secure/ is where my files are hosted

The application itself is only around 7mb.

The files for these users are around 600mb

I have two pretty high-level questions to ask.

  1. Should I be using express.js for this? I have a feeling Node.js doesn't shine in this scenario and I've had a lot of difficulty searching for tutorials for more complex user authentication (user groups/roles). RoR?

  2. Should my files sit outside of the application? In a database? s3 bucket? At the moment I have set up a static route to a folder that sits within the application directory called secure, I then have some middleware that checks all requests to secure/ and checks if the user is authorised (see code below). I'm asking this as I have a limit of 512mb uploads with Elastic Beanstalk

    app.all('/secure/*', function(req, res, next) { if (req.isAuthenticated()) { next(); // allow the next route to run } else { // require the user to log in res.redirect("/"); } }); app.use('/secure', express.static(config.root + '/secure'));

Even if someone could provide me some resources that would be great! Thanks


Solution

    1. Express.js is as good as RoR or anything else. No further comments.
    2. Yes, absolutely. Your files must sit outside of the application. In almost all scenarios that require persistent storage, you're better off using the persistent and reliable storage solutions such as S3. And, shipping the secure files along with your application code is not a good idea. As for elastic beanstalk, the EC2 instance(s) launched to serve your application do not have persistent local storage and hence on the instance termination, your data will be lost. Apart from that, you will have problems with auto-scaling where one of your instance can not access files in another instance. Assuming you are using AWS, I suggest you to use S3. You can also look into one of the AWS's new storage solution: Elastic File System