TheGame TimeMachine
TheGame TimeMachine

Reputation: 75

Nested Callbacks with NodeJS & MySQL

I have come to a time in my java-script adventure where I have needed to nest callbacks. I have the following code. I keep reading bout nested callbacks being hell... if someone could explain or help with the code. I am still very new to asynchronous programming. I am using nodejs, express 3.0, jade, node-mysql

db_helper.getCategory(function (category) {
    db_helper.getCities(function (cities) {
             res.render('/search', category: category, cities: cities });

    });
});

i apologize for not really asking. Im wondering if this is ok to do this? Whats a better way to handle nested callbacks?

Upvotes: 0

Views: 443

Answers (1)

go-oleg
go-oleg

Reputation: 19480

Take a look at the async npm module. It helps with organizing callbacks and avoiding the deep nesting you are referring to. Perhaps the waterfall would help.

Upvotes: 2

Related Questions