New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

regex-router

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regex-router

Route http requests via regular expressions.

0.1.5
Source
npm
Version published
Weekly downloads
46
475%
Maintainers
1
Weekly downloads
 
Created
Source

Regex-router

Regex-router is a simple Node.js library to simplify routing. And by simplify, I mean 39 lines of code.

Example

var fs = require('fs'),
  http = require('http'),
  Router = require('regex-router'),
  r = new Router();

r.get(/^\/page\/(\w+)/, function(m, req, res) {
  console.log('Serving URL:', req.url);
  var page_name = m[1],
    page_path = __dirname + '/static_pages/' + page_name + '.html';
  fs.readFile(page_path, 'utf8', function(err, html) {
    res.write(html);
    res.end();
  });
});

r.default = function(m, req, res) {
  res.end('404. URL not found:', req.url);
})

http.createServer(function(req, res) {
  r.route(req, res);
}).listen(80, 'localhost');

Keywords

http

FAQs

Package last updated on 27 May 2013

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