Friday 19 October 2018

Node cli: --trace-warnings

‘--trace-warnings’ print stack traces for process warnings (including deprecations).

HelloWorld.js
var EventEmitter = require('events').EventEmitter;

EventEmitter.defaultMaxListeners = 3;

var emitter = new EventEmitter();

emitter.on('demo',() => {
 console.log("listener1");
});

emitter.on('demo',() => {
 console.log("listener2");
});

emitter.on('demo',() => {
 console.log("listener3");
});

emitter.on('demo',() => {
 console.log("listener4");
});

emitter.emit('demo')


Run HelloWorld.js using below command.
node --trace-warnings HelloWorld

You can see below kind of output.

listener1
listener2
listener3
listener4
(node:27700) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 4 demo listeners added. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:243:17)
    at EventEmitter.addListener (events.js:259:10)
    at Object.<anonymous> (C:\Users\krishna\Documents\Study\nodejs\examples\HelloWorld.js:19:9)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)

Previous                                                 Next                                                 Home

No comments:

Post a Comment