# express-dir-routing

> express.js file-based routing system

Latest version **1.1.3** (published 2025-01-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install express-dir-routing
pnpm add express-dir-routing
yarn add express-dir-routing
bun add express-dir-routing
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2025-01-06 |
| First published | 2023-05-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | github.com/lullaby6 |
| Maintainers | lullaby6 |
| Keywords | express, expressjs, routing, router, routing, nextjs, next |

## Links

- npm: https://www.npmjs.com/package/express-dir-routing
- Repository: https://github.com/lullaby6/express-dir-routing
- Issues: https://github.com/lullaby6/express-dir-routing/issues
- npm.io page: https://npm.io/package/express-dir-routing

## Dependencies (1)

- [express](https://npm.io/package/express.md) ^4.18.2

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.1.3 (latest) — 2025-01-06
- 1.1.2 — 2025-01-06
- 1.1.1 — 2025-01-06
- 1.1.0 — 2025-01-06
- 1.0.4 — 2023-06-01
- 1.0.3 — 2023-05-31
- 1.0.2 — 2023-05-31
- 1.0.0 — 2023-05-31

## README

# express-dir-routing

A file-based routing system for `express.js` using directories like `NextJS 13` or `SvelteKit`!

# Installation

```sh
npm install express-dir-routing
```

# Usage

```
routes
├── get.js
├── users
│   ├── get.js
│   ├── post.js
│   └── $username
│       └── get.js
└── products
    └── get.js
    └── post.js
    └── put.js
    └── delete.js
        └── $id
            └── get.js
```

also you can rename `get.js` files with `get.user.js` or `get.products.js`:

```
routes
├── get.js
├── users
│   ├── get.users.js
│   └── $username
│       └── get.users-username.js
└── products
    └── get.products.js
    └── $id
        └── get.products-id.js
```

```js
// app.js
const express = require('express')
const path = require('path')
const { dirRouter } = require('express-dir-routing');

const app = express();

app.use('/', dirRouter(path.join(__dirname, 'routes')));
```

```js
// routes -> users -> get.users.js
function controller(req, res){
    res.send('GET user');
}

module.exports = controller
```

and you can get URL params naming a directory with $ like "$username"

```js
// routes -> users -> $username -> get.users-username.js
function controller(req, res){
    const {username} = req.params;

    res.send(`GET user ${username}`);
}

module.exports = controller
```

# License

MIT

---
_Source: https://npm.io/package/express-dir-routing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
