【发布时间】:2017-03-03 12:04:19
【问题描述】:
我创建了一个 Azure 时间触发函数,我想和他一起读取 Json 文件。我确实安装了 read-json 和 jsonfile 包并尝试了两者,但它不起作用。这是一个示例函数
module.exports = function (context, myTimer) {
var timeStamp = new Date().toISOString();
var readJSON = require("read-json");
readJSON('./publishDate.json', function(error, manifest){
context.log(manifest.published);
});
context.log('Node.js timer trigger function ran!', timeStamp);
context.done();
};
这是错误:
TypeError: Cannot read property 'published' of undefined
at D:\home\site\wwwroot\TimerTriggerJS1\index.js:8:29
at ReadFileContext.callback (D:\home\node_modules\read-json\index.js:14:22)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:365:13).
Json 文件与 index.js 位于同一文件夹中。我假设这个错误是因为路径'./publishDate.json'而发生的,如果是这样我应该如何输入一个有效的路径?
【问题讨论】:
标签: json node.js azure azure-functions