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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -