Is this the correct way to have asynchronous functions only run once within express? I don't want this function to have to run on every route. I'm looking for an express-friendly way to do this.
var packageJson = false
app.use(function(req, res, next){
if(req.packageJson) return next()
if(packageJson){
req.packageJson = packageJson
return next()
}
return fs.readFileAsync("./package.json", "utf8")
.then(JSON.parse)
.then(function(data){
packageJson = data
req.packageJson = data
return next()
})
})