phuocdh-util
v0.1.0
Published
My simple utilities
Downloads
5
Readme
Node.js utilities
A collection of simple Node.js utilities
Contents
1. Mvc util (Node.js only)
Easily setup Express route controllers. Can define custom policy for each handler.
// require the module
let { PMvc } = require('phuocdh-util')
// with custom policy
let MvcUtil = new PMvc(require('policy object path'))
// or without policy
let MvcUtil = new PMvc()
// load all controllers
let controllers = MvcUtil.listController('controller folder path')
// setup Express routes
MvcUtil.setup(expressApp, controllers)
// wait for all controllers to be initialized.
// if there is no controller with async init() method, there is no need to call this function
await MvcUtil.init(controllers)
2. Console util (Node.js only)
Write console log in NodeJS with styles!
let { PConsole } = require('phuocdh-util')
// log
PConsole.log('tag', 'message 01', 'message 02')
// warm
PConsole.warn('tag', 'message 01', 'message 02')
// error
PConsole.error('tag', 'message 01', 'message 02')
// assert
PConsole.assert(false, 'tag', 'message 01', 'message 02')
3. Math util
let { PMath } = require('phuocdh-util')