相关疑难解决方法(0)

异步nodejs模块导出

我想知道配置模块导出的最佳方法是什么.以下示例中的"async.function"可能是FS或HTTP请求,为了示例而简化:

这是示例代码(asynmodule.js):

var foo = "bar"
async.function(function(response) {
  foo = "foobar";
  // module.exports = foo;  // having the export here breaks the app: foo is always undefined.
});

// having the export here results in working code, but without the variable being set.
module.exports = foo;
Run Code Online (Sandbox Code Playgroud)

如何在执行异步回调后才导出模块?

编辑 我的实际用例的快速说明:我正在编写一个模块来在fs.exists()回调中配置nconf(https://github.com/flatiron/nconf)(即它将解析配置文件和设置nconf).

asynchronous node.js

63
推荐指数
5
解决办法
5万
查看次数

标签 统计

asynchronous ×1

node.js ×1