Find My Way HTTP Router

9.5.0 · active · verified Tue Apr 21

find-my-way is a high-performance HTTP router for Node.js, currently at version 9.5.0, designed for speed using a Radix Tree implementation. It is framework-independent and supports advanced routing features such as route parameters, wildcards, and versioned routes. The project maintains an active release cadence, with recent updates focusing on performance improvements, Node.js version compatibility (requiring Node.js >=20), and security fixes. Key differentiators include its proven speed, demonstrated in benchmarks against other popular routers, and its direct use in major frameworks like Fastify and Restify, indicating robustness and reliability for production environments. It also provides a comprehensive API for route management including `on`, `off`, `findRoute`, `hasRoute`, and `lookup`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic HTTP server creation, defining GET and POST routes, handling route parameters, and using `find-my-way`'s `lookup` method to dispatch incoming requests.

const http = require('http')
const FindMyWay = require('find-my-way')
const router = FindMyWay()

router.on('GET', '/', (req, res, params) => {
  res.end('{"message":"hello world"}')
})

router.on('GET', '/user/:id', (req, res, params) => {
  res.end(`{"message":"hello user ${params.id}"}`)
})

router.on('POST', '/data', (req, res) => {
  let body = ''
  req.on('data', chunk => { body += chunk })
  req.on('end', () => {
    res.end(`Received data: ${body}`)
  })
})

const server = http.createServer((req, res) => {
  router.lookup(req, res)
})

server.listen(3000, err => {
  if (err) throw err
  console.log('Server listening on: http://localhost:3000')
  console.log('Try visiting http://localhost:3000 and http://localhost:3000/user/123')
  console.log('Or curl -X POST -d "test" http://localhost:3000/data')
})

view raw JSON →