Reading Swagger's x-api-key in express


Swagger's authentication is generally done using x-api-key header. Like shown in following image

Following is the respective express code to read the x-api-key from the header.

router.get('/products', (req, res) => {
    const token = req.headers['x-api-key'];
    // validate the key...
    // rest of the business logic
});