2.0.2 • Published 4 years ago

routerfy v2.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

routerfy

Nuxt like router for Express

NPM

install

npm install routerfy

Usage

Routerfy automatically generates the routes based on your file tree inside the routes directory.

const express = require('express')
const routerfy = require('routerfy')

const app = express()

app.use(routerfy('routes'))

app.listen(8080)

Basic routes

This file tree:

routes/
--| user/
-----| index.js
-----| one.js
--| index.js

will automatically generate:

  • /
  • /user
  • /user/one

Dynamic routes

To define a dynamic route with a parameter, you need to define a JavaScript file OR a directory prefixed by an underscore.

This file tree:

routes/
--| _slug/
-----| comments.js
-----| index.js
--| users/
-----| _id.js
--| index.js

will automatically generate:

  • /
  • /users/:id
  • /:slug
  • /:slug/comments

Note: For dynamic routes to work properly, you must use the mergeParams: truejavascript option when calling the express.Router function

const router = require('express').Router({ mergeParams: true });

router.get('/', (req, res) => {
	res.send(req.params.slug);
});

module.exports = router;
2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago