Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lullaby6/express-dir-routing
NPM Package - File-based routing system for express.js
https://github.com/lullaby6/express-dir-routing
express express-js node node-js nodejs npm npm-package routing
Last synced: 8 days ago
JSON representation
NPM Package - File-based routing system for express.js
- Host: GitHub
- URL: https://github.com/lullaby6/express-dir-routing
- Owner: lullaby6
- Created: 2023-05-31T01:37:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-06T18:13:19.000Z (27 days ago)
- Last Synced: 2025-01-06T18:26:08.971Z (27 days ago)
- Topics: express, express-js, node, node-js, nodejs, npm, npm-package, routing
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/express-dir-routing
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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