
Security News
Node.js Drops Bug Bounty Rewards After Funding Dries Up
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.
express-version-request
Advanced tools
versions an incoming request to Express based on header or URL
This npm package provides an ExpressJS middleware that sets the request object with a version property by parsing a request HTTP header.
If you wish to employ your own logic in some middleware/configuration and set the request version programmaticaly and not by parsing a specific HTTP header:
const versionRequest = require('express-version-request')
app.use(versionRequest.setVersion('1.2.3'))
Then in later middlewares you will be able to access req.version property and it's value set to 1.2.3.
By default, the library will parse the version out of the X-Api-Version HTTP header:
const versionRequest = require('express-version-request')
app.use(versionRequest.setVersionByHeader())
If you wish to advise the library which HTTP header to parse to extract the version:
const versionRequest = require('express-version-request')
app.use(versionRequest.setVersionByHeader('My-HTTP-Header-Name'))
By default, the library will parse the version out of the api-version query parameter:
const versionRequest = require('express-version-request')
app.use(versionRequest.setVersionByQueryParam())
If you wish to advise the library which query parameter to parse to extract the version:
const versionRequest = require('express-version-request')
app.use(versionRequest.setVersionByQueryParam('myQueryParam'))
The second parameter of setVersionByQueryParam is an options object.
By default, the library will parse the version from the Accept header, expecting the following format: Accept: application/vnd.company+json;version=1.0.0 For more details about the Accept header format, please refer to the RFC.
const versionRequest = require('express-version-request')
app.use(versionRequest.setVersionByAcceptHeader())
As a fallback, the lib supports an alternative Accept header format:
Accept: application/vnd.comapny-v1.0.0+json
or
Accept: application/vnd.comapny.v1.0.0+json
The lib will try to parse the header using the default format, and if it doesn't succeed, tries this alternative format. The usage is the same as in the case of the regular format:
const versionRequest = require('express-version-request')
app.use(versionRequest.setVersionByAcceptHeader())
If you wish to use your own parsing, it is possible to pass a function as the first parameter. The lib will then call it with the actual value of the Accept header as the first parameter, and the returned value will be set as version. The provided function should return a string.
const versionRequest = require('express-version-request')
function customParsingFunction(header) {
//function body, that parses the header parameter and returns a string
}
app.use(versionRequest.setVersionByAcceptHeader(customParsingFunction))
Before setting the version, it is always formatted, so the resulting version is a semver comaptible string, except the following cases:
This formatting function is called automatically for each version setting method, but it can also be used independently:
const versionRequest = require('express-version-request')
const formattedVersion = versionRequest.formatVersion(versionThatNeedsFormatting)
removeQueryParam
Delete version HTTP query parameter after setting the request object with a version property.
By default it is set to false.
const versionRequest = require('express-version-request')
const options = {removeQueryParam: true}
app.use(versionRequest.setVersionByQueryParam('myQueryParam', options))
If you define a middleware after versionRequest then you can verify that the version is indeed set:
app.use((req, res, next) => {
console.log(req.version)
next()
})
yarn add express-version-request
yarn test
Project linting:
yarn lint
yarn test:coverage
The project uses the commitizen tool for standardizing changelog style commit messages so you should follow it as so:
git add . # add files to staging
yarn commit # use the wizard for the commit message
Liran Tal liran.tal@gmail.com
FAQs
versions an incoming request to Express based on header or URL
The npm package express-version-request receives a total of 1,110 weekly downloads. As such, express-version-request popularity was classified as popular.
We found that express-version-request demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.