javascript - Node.js Express: loading JSON file only on server startup -
i'm working on express.js app should load api definition file (most swagger file in json format). i've created middleware, should parse json file via fs.readfile()
, json.parse()
in order check user's permissions on accessing resource. each time request performed, middleware gets same json file , parses it, piece of work. possible load json file, parse , store internal object in sort of global configuration , reload in case modified not perform same operation on each request?
of course, create function (pseudo code):
var jsondata=null; function getconfiguration() { if (!jsondata) { jsondata= readfilesync(...); } return jsondata; } module.exports.getconfiguration=getconfiguration;
or, @aleksandrm commented, can "import" using require:
Comments
Post a Comment