npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lws-redirect

v2.1.2

Published

Perform a 302 Redirect if the request URL matches a specified regular expression

Readme

view on npm npm module downloads Build Status Dependency Status js-standard-style

lws-redirect

A lws middleware plugin to perform a 302 Redirect if the request URL matches a specified regular expression.

Adds the following option to lws.

--redirect expression ...   A list of URL redirect rules. For each rule, separate the 'from' and 'to'
                            expressions with '->'. Whitespace surrounding the expressions is ignored.
                            E.g. 'http -> https'.

Usage

Supply a "from" regular expression and "to" replace string. If the request URL matches the "from" regexp, the matching "from" string will be replaced by the "to" string.

Some examples if the incoming request URL is http://localhost:

  • --redirect 'http -> https' would redirect to https://localhost.
  • --redirect 'http -> https' 'localhost -> remotehost' would redirect to https://remotehost.
$ npm install --save-dev lws-redirect

$ lws --port 80 --stack lws-redirect --redirect 'http -> https'
Listening on http://mba4.local:80, http://127.0.0.1:80, http://192.168.0.200:80

$ $ curl -I http://127.0.0.1/
HTTP/1.1 302 Found
Location: https://127.0.0.1/
Content-Type: text/html; charset=utf-8
Content-Length: 67
Date: Sun, 09 Jun 2019 16:53:38 GMT
Connection: keep-alive

Debugging

This package includes a trivial command-line tool for testing redirect rules. Test each rule individually using this command structure:

$ npx lws-redirect <from> <to> <url>

The following examples test a rule which adds a trailing / to a path ending with one or two. The first two examples produce a match and modified target URL. The third and fourth examples do not produce a match so the target URL remains unmodified.

Note: Windows users may need to use double instead of single quotes.

$ npx lws-redirect '(one|two$)' '$1/' http://something.com/one
http://something.com/one/

$ npx lws-redirect '(one|two$)' '$1/' http://something.com/two
http://something.com/two/

$ npx lws-redirect '(one|two$)' '$1/' http://something.com/three
http://something.com/three

$ npx lws-redirect '(one|two)$' '$1/' http://something.com/one/four
http://something.com/one/four

Tutorials


© 2019-20 Lloyd Brookes <[email protected]>.