1.2.1 • Published 6 years ago

dasjs v1.2.1

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

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
}
1.2.1

6 years ago

1.2.0

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