named-counter

1.0.13 • Public • Published

du-node-utils

dueros node utils

NPM version npm download David deps

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();
});

Readme

Keywords

none

Package Sidebar

Install

npm i named-counter

Weekly Downloads

1

Version

1.0.13

License

MIT

Unpacked Size

4.24 kB

Total Files

3

Last publish

Collaborators

  • imcooder