named-counter
v1.0.13
Published
named counter
Downloads
3
Readme
du-node-utils
dueros node utils
install
npm install named-counter -S
usage
const namedCounter = require('named-counter');
namedCounter.increase('all_cnt');
namedCounter.increaseOnce(req, 'req_cnt');
namedCounter.decrease('all_cnt');
namedCounter.decrease(req, 'req_cnt');
namedCounter.toString() // all_cnt:2 样式string
increaseOnce: an same object increase once decreaseOnce: an same object decrease once
example
express.use((req, res, next) => {
namedCounter.increase('all_cnt');
namedCounter.increaseOnce(req, 'req_cnt');
onFinished(res, (err, res) => {
namedCounter.decreaseOnce(req, 'req_cnt');
namedCounter.decrease('all_cnt');
if (err) {
logger.warn('logid:%s onFinish error:%s', logid, err.stack);
}
console.log(namedCounter.toString());
});
next();
});