req-meta-middleware
An Express middleware for parsing various request metadata. The following data are parsed from the request object:
- Referer information using database from referer-parser
- UTM tags
- IP address and its geoip info
- User-Agent using ua-parser-js
Installation
npm:
npm install req-meta-middleware
yarn:
yarn add req-meta-middleware
Usage
Add req-meta-middleware to your middleware stack.
Note that we need to await
for the middleware to initialize.
; ;// ...app.useawait meta;
All parsed information is stored at req.meta
.
app.use;
Options
You can also specify options while initializing the middleware.
;server.usemetaoptions;
See the node-cron docs for the cron schedule syntax.
Parsing after response
If req.meta
isn't used for building responses, it may be faster in response time to parse the request after sending the response.
(eg. only using metadata for referral stats)
In that case, use later
to parse metadata after the response has been sent.
;server.useawait meta.laterhandler, options;
The middleware will first call next()
to further process the request, then parse and callback after the response has been sent.