如何从nodejs中的promise获取返回值?

时间:2017-08-24 18:37:44

标签: javascript node.js

我是Javascript和Nodejs的新手所以这个问题可能听起来很基本。我正在尝试从其他地方获取promise返回的值。我尝试使用getter方法,并尝试使用全局变量并将其分配给局部变量来获取它但我仍然有困难。

    var initCounter = 0;
    function sql_count() {
    sql_connection.User.count().then(function (count) {
        if(count) {
         initCounter= count; //-> I would like to get the value of count.
         console.log(initCounter);
         return initCounter;
        }

    });
};

0 个答案:

没有答案