-1

I have a method which is typed with: Express.Request How can I access headers within this method?

Example Code:

    private _onTokenReceived(req: Express.Request, res: Express.Response): void {
        const header: string = req.headers.authorization;
    }

In my example headers is not reachable.

Error: The "headers" property does not exist for the "Request" type.ts(2339)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
HOST-X
  • 185
  • 10

1 Answers1

0

Following this answer on stackoverflow, if you use Express 4.x, you can use the req.get(headerName) method as described in Express 4.x API Reference.

Juliano Silva
  • 288
  • 1
  • 10