Skip to content
/ dasjs Public

it helps you to modulate callbacks for express routes. router.post('/user', 'UserController@create')

License

Notifications You must be signed in to change notification settings

anbturki/dasjs

Repository files navigation

DasJs/Router

NOTE: this is not stable yet, you may face some issues cause it's still under development.

Add more features to Express routes.

It helps you to modulate express routes. router.post('/user', 'UserController@create'), without needs to require controllers everywhere.

Installation

npm install dasjs --save

Usage Example

# server.js
const express = require('express')
const app = express()

// the first paramter is express() instance
/*
* the second parameter is application root path where the controllers directory is located.
* the controllers directory will be automatically created if it does not exists.
* you can change the controllers directory name by passing the new name in the third parameter.
*/
const router = require('dasjs').Router(app, __dirname)

router.get('/user', 'UserController@index')
router.post('/user', 'UserController@create')
router.put('/user/:id', 'UserController@update')
router.delete('/user/:id', (request) => {
  const params = request.params // going to improve it
  // rest of code
  return {
    success: true
  }
})

// multi verbs for one route
router.route('/post', (req, res) => {}, ['get', 'post'])

app.listen(3000)

and

# controllers/UserController.js
module.exports = {
  index (req, res, next) {},
  async create (req, res) {}
  // ... and so on
}

About

it helps you to modulate callbacks for express routes. router.post('/user', 'UserController@create')

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published