While coding, I was wondering if it's better to require all my libraries at the top of the file, even not all middleware needs it.For exampleconst AWS = require('aws-sdk'); const s3 = new AWS.s3({/* credentials */}); app.post('/update-profile', (req, resp) => { // Store uploaded profile pic in s3 }); app.post('/change-password', (req, resp) => { // AWS s3 is not used here }); Would it be better to move the const AWS and s3 into the /update-profile middleware? Would this lower the memory used when running my node server? What is the trade-off putting the require inside a middleware? More overhead on the request/response?
Submitted April 22, 2020 at 01:02PM by eggtart_prince
No comments:
Post a Comment