Bruce Dou
Bruce Dou

Reputation: 4771

Nodejs Callback or eventEmitter

Which is the best practice to write nodejs code.

There are so many callback in my current code and reduced the readability.

Any suggestion?

Upvotes: 2

Views: 7060

Answers (2)

Abhishek Garg
Abhishek Garg

Reputation: 201

Callback: Use a callback if you just want to execute some code at a certain time and you don't need to emit success or failure.

EventEmitter: Use this if your object emits lots of types of events.

Upvotes: 1

yojimbo87
yojimbo87

Reputation: 68453

Try to look at some flow control libraries and articles in answer to this question: Async programming paradigm with nodejs and redis-node.

Upvotes: 0

Related Questions