0.2.2 • Published 4 years ago

directory-routes v0.2.2

Weekly downloads
17
License
MIT
Repository
github
Last release
4 years ago

Directory Routes

Directory Routes allows you to require modules in a folder deeply and pair all exports with their relative path to the required folder.

What is this good for? We can use this for very cleanly organizing our HTTP endpoints using file/directory structures.

For example let's say we have a folder called routes, and it has this directory structure# Directory Routes Directory Routes allows you to require modules in a folder deeply and map all exports to their full relative path to the required folder.

Installing

npm i -s directory-routes

Example

What is this good for? We can use this for very cleanly organizing our HTTP endpoints using file/directory structures.

For example let's say we have a folder called routes, and it has this directory structure

- routes
  |- auth
  |  |- login.js
  |  |- signup.js
  |  |- logout.js
  |- news
     |- latest.js
     |- between.js

Now if we require the routes directory with Directory Routes like this we can see Directory Routes doing it's magic.

const directoryRoutes = require('directory-routes')
directoryRoutes(__dirname + '/routes', (err, routes) => {
	if (err) return console.log(err)
    console.log(routes)
})

We should now see this from the routes being logged.

[
    ["/auth/login", (login export)],
    ["/auth/signup", (signup export)],
    ["/auth/logout", (logout export)],
    ["/news/latest", (latest export)],
    ["/news/between", (between export)]
]

Additionally, Directory Routes returns a promise that you can use instead of a callback.

0.2.1

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

6 years ago

0.1.33

6 years ago

0.1.32

6 years ago

0.1.31

6 years ago

0.1.3

6 years ago

0.1.25

6 years ago

0.1.24

6 years ago

0.1.23

6 years ago

0.1.22

6 years ago

0.1.21

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago