Skip to content

Tag: node.js

Is console.log atomic?

The print statement in Python is not thread-safe. Is it safe to use console.log in Node.js concurrently? If so, then is it also interleave-safe? That is, if multiple (even hundreds) of callbacks write to the console, can I be sure that the output won’t be clobbered or interleaved? Looking at the source …

How to print object in Node JS

In the below code (running on Node JS) I am trying to print an object obtained from an external API using JSON.stringify which results in an error: TypeError: Converting circular structure to JSON I have looked at the questions on this topic, but none could help. Could some one please suggest: a) How I could …

Allow only certain events

Is there a way to only allow certain events in a custom eventEmitter? For example, if I have something like this everything works as expected: I get a callback every second on the first event and every 2 seconds on the 2nd event. For the 3rd nothing happens, because I don’t emit this event. Is there a w…