Skip to content
This repository has been archived by the owner on May 3, 2020. It is now read-only.

Latest commit

 

History

History
49 lines (40 loc) · 1.61 KB

README.md

File metadata and controls

49 lines (40 loc) · 1.61 KB

path match

NPM version Node.js CI codecov Dependency Status License Downloads

Thin wrapper around path-to-regexp to make extracting the param names easier.

var route = require('path-match')({
  // path-to-regexp options
  sensitive: false,
  strict: false,
  end: false,
});

// create a match function from a route
var match = route('/post/:id');

// match a route
var parse = require('url').parse;
require('http').createServer(function (req, res) {
  var params = match(parse(req.url).pathname);

  // no match
  if (params === false) {
    res.statusCode = 404;
    res.end();
    return;
  }

  // the matched id
  var id = params.id;

  // do stuff with the ID
})