absolute-url
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/absolute-url package

2.0.0 • Public • Published

absolute-url

build status npm version

Get the absolute URL of an Express request object.

Install

npm install --save absolute-url

Usage

The library offers two ways to use the functionality:

Function

The default export is a function that can be called with the Express request object as a parameter. It returns the absolute URL as a URL object.

import absoluteUrl from 'absolute-url'

app.use((req, res, next) => {
  console.log(absoluteUrl(req))

  next()
})

See examples/function.js for a full working example.

Middleware

The package also exports a middleware factory function. It can be used to attach a .absoluteUrl method to the Express request object. The method returns the absolute URL as a URL object.

import { middleware } from 'absolute-url'

app.use(middleware())

app.use((req, res, next) => {
  console.log(req.absoluteUrl())

  next()
})

See examples/middleware.js for a full working example.

/absolute-url/

    Package Sidebar

    Install

    npm i absolute-url

    Weekly Downloads

    91

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    14.5 kB

    Total Files

    11

    Last publish

    Collaborators

    • bergos