Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-urlrewrite

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-urlrewrite

URL rewrite middleware for express

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
192K
decreased by-23.67%
Maintainers
1
Weekly downloads
 
Created

What is express-urlrewrite?

The express-urlrewrite package is a middleware for Express.js that allows you to rewrite URLs based on specified patterns. This can be useful for redirecting traffic, simplifying URLs, or handling legacy URL structures.

What are express-urlrewrite's main functionalities?

Simple URL Rewriting

This feature allows you to rewrite a simple URL from '/old-path' to '/new-path'. When a user visits '/old-path', they will be served the content from '/new-path'.

const express = require('express');
const rewrite = require('express-urlrewrite');
const app = express();

app.use(rewrite('/old-path', '/new-path'));

app.get('/new-path', (req, res) => {
  res.send('This is the new path');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Pattern-based URL Rewriting

This feature allows you to rewrite URLs based on patterns. In this example, any URL matching '/user/:id' will be rewritten to '/profile/:id', where ':id' is a dynamic parameter.

const express = require('express');
const rewrite = require('express-urlrewrite');
const app = express();

app.use(rewrite('/user/:id', '/profile/:id'));

app.get('/profile/:id', (req, res) => {
  res.send(`Profile ID: ${req.params.id}`);
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Regular Expression URL Rewriting

This feature allows you to use regular expressions for URL rewriting. In this example, any URL matching the pattern '/old-<number>' will be rewritten to '/new/<number>'.

const express = require('express');
const rewrite = require('express-urlrewrite');
const app = express();

app.use(rewrite(/^\/old-(\d+)$/, '/new/$1'));

app.get('/new/:id', (req, res) => {
  res.send(`New ID: ${req.params.id}`);
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Other packages similar to express-urlrewrite

Keywords

FAQs

Package last updated on 02 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc