简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM