Registry / http-networking / lws-rewrite

lws-rewrite

JSON →
library4.0.0jsnpmunverified

lws-rewrite is a middleware plugin for lws (Local Web Server) that adds URL rewriting support. Current stable version is 4.0.0, released under the ISC license. It allows defining rewrite rules via command-line options to map source URLs to local or remote destinations, supporting pattern-based replacements. Key differentiator: integrates seamlessly with lws's plugin architecture and its wiki provides detailed usage examples. The project is maintained with regular updates, compatible with Node.js >=12.17.

npm install lws-rewrite
INSTALL
IMPORT
SIG · LWS-REWRITE
L
lws-rewrite
http-networkingjavascriptv4.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lws
import lws from 'lws'
const lws = require('lws')
lws itself is ESM-only since v4, but lws-rewrite is loaded as a plugin, not directly imported.
Rewrite
import Rewrite from 'lws-rewrite'
const Rewrite = require('lws-rewrite')
The plugin is exported as a default class; CommonJS require is not supported as the package is ESM-only.
lws command line
npx lws --rewrite '/old -> /new'
node server.js --rewrite ...
Rewrite rules are passed via CLI to lws, not used programmatically in most cases.

Demonstrates programmatic usage of lws-rewrite plugin with lws, setting up rewrite rules to proxy API requests and redirect a path.

import lws from 'lws' import Rewrite from 'lws-rewrite' const server = lws.create({ port: 8080, stack: [new Rewrite()], rewrite: [ '/api/* -> http://localhost:3000/api/$1', '/old-path -> /new-path' ] }) server.start().then(() => { console.log('Server started on http://localhost:8080') })
Debug
Known issues
gotchaRewrite rules must use '->' with spaces; missing spaces will cause the rule to be ignored.
fix
Use format '/from -> /to' with spaces around '->'.
affects: >=0.0.0
breakingVersion 4.0.0 dropped support for Node.js <12.17 and switched to ESM-only.
fix
Upgrade to Node.js >=12.17 and use ESM imports.
affects: >=4.0.0
deprecatedThe '--rewrite' option replaces older '--map' or custom middleware; use '--rewrite' for current API.
fix
Use '--rewrite' instead of deprecated options.
affects: >=2.0.0
gotchaRules are applied in order; first matching rule wins, which may lead to unexpected behavior if overlapping patterns.
fix
Order rules from most specific to least specific.
affects: >=0.0.0
gotchaRewriting to remote destinations does not alter the Host header; remote server may reject requests.
fix
Use lws proxy middleware for full proxy support.
affects: <4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'lws-rewrite'
Package not installed or not in node_modules.
fix
Run 'npm install lws-rewrite' in your project.
TypeError: lws_rewrite_1.default is not a constructor
Using CommonJS require() with an ESM-only package.
fix
Use ESM import: import Rewrite from 'lws-rewrite'
lws: rewrite rule '/old-> /new' is invalid. Must contain ' -> ' (space-dash-greaterthan-space)
Rule syntax missing required spaces around '->'.
fix
Use correct format: '/old -> /new'
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
lwsrequiredpeer dependency - this plugin is designed to be used with lws
Agent activity
2 hits · last 30 days
node
2
Resources
lws-rewrite — npm install lws-rewrite · libregistry