• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 1 year ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

💫 A file-based routing for Node.js. Works with Bun, pure Node.js, Express.js, and more!

Node File Router

ci Status npm downloads license

A powerful file-based routing for Node.js.

  • Technology Agnostic:
    • Pure Node HTTP
    • Bun
    • Express
    • Sockets
    • ... whatever compatible with the interface
  • 0 dependencies
  • CommonJS and ES modules support
  • TypeScript support
  • 100% test coverage
api/
├── profile/
│   └── orders.[post].ts - methods in any filenames
├── catalog/
│   └── [[...tags]].ts - several segments
├── collection/
│   └── [cid]/ - slugs in folders
│       └── products/
│           └── [pid].ts - slugs in files
├── index.ts - root
└── _404.ts - not found response    
  • [POST]: /profile/orders → /api/profile/orders.[post].ts
  • /catalog/men/black/denim → /api/catalog/[[...tags]].ts
  • /collection/77/products/13 → /api/collection/[cid]/products/[pid].ts
  • / → index.ts

Methods in a file:

export default {
  get(req, res, routeParams) {},
  post(req, res, routeParams) {},
  patch(req, res, routeParams) {},
}

Single response function:

export default function (req, res, routeParams) {}

Documentation

Visit website to get started and view the full documentation.

Usage:

Methods routing:

Route matching:

Support other protocols and frameworks:

Examples

Visit examples folder to see samples with different module systems, adapters, and use cases.

Developing

To begin development and contribution, read this guide.

Community

Ask questions, voice ideas, and share your projects on Github Discussion.