how to inspect nodejs express middleware options and parameters

75 Views Asked by At

I would like to inspect some middleware options I am setting for express later in the code. For instance I am setting limits in json bodyParser as:

expressServer.use(bodyParser.json({
  limit:1000000
}))

Then later in the code I would like to retrieve that value from the express instance for further needs.

To use this "limit" as a global variable would not be a desired solution.

1

There are 1 best solutions below

2
On

You can store options in database or in a simple file:

{
    "bodyParserLimit": 10000
}

And then access it by reading file

// implement this function
readOptionsFromFile(function() {
    expressServer.use(bodyParser.json({
       limit: options.bodyParserLimit
    }))
})

So you can call readOptionsFromFile(callback) from wherever you want.