Skip to content
Advertisement

is it possible to make an on(consolelog event? it would do something every time text is logged to console

This feature would do something every time text is logged to the node.js console. Here’s a somewhat of example of how I think it should look like:

on('console', msg => {console.log("text was logged! " + msg)})

Regular node.js

Advertisement

Answer

Console methods don’t emit events, but the console object and its methods can be overwritten, so you could redefine it yourself: console.log = (...args) => { process.stdout.write('logged: ' + args.join(' ')) }, or wrap it in a Proxy.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement