Skip to content
/ exruxt Public

A Nuxt like router for Express, supports JavaScript & TypeScripts terminations.

License

Notifications You must be signed in to change notification settings

wasmake/exruxt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exruxt

A Nuxt like router for Express, supports JavaScript and TypeScript files

NPM

install

npm install exruxt

Usage

Exruxt will generate the routes based on your file tree inside the routes directory.

const express = require('express')
const exruxt = require('exruxt')

const app = express()

app.use(exruxt('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;

About

A Nuxt like router for Express, supports JavaScript & TypeScripts terminations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published