如何从nodejs中的azure函数更新json文件?
我能够从azure函数中读取JSON文件,而且我还希望更新JSON文件,这是我尝试过的代码。
module.exports = async function (context, myTimer) {
var axios = require('axios')
var path = require('path')
var fs = require('fs')
var update_json = require('json-update')
var response = await axios.get('.json')
await update_json.update('D:\home\site\wwwroot\TimerTrigger2\holiday.json',{'name':"jeeva"})
var data2 = await update_json.load('D:\home\site\wwwroot\TimerTrigger2\holiday.json')
context.log(data2.name)
context.log(typeof JSON.stringify(response['data']['data']))
context.log(typeof response['data']['data'])
return response['data']['data']
};
这是我的json文件。
{
"name":"saran"
}
这里我使用的是json-update包,我也同意其他一些包,我该怎么办?
回答如下:您还可以使用“ edit-json-file”包来更新json,我在下面发布了我的代码供您参考:
有关“ edit-json-file”的更多信息,请参见this页面。
如何从nodejs中的azure函数更新json文件?
我能够从azure函数中读取JSON文件,而且我还希望更新JSON文件,这是我尝试过的代码。
module.exports = async function (context, myTimer) {
var axios = require('axios')
var path = require('path')
var fs = require('fs')
var update_json = require('json-update')
var response = await axios.get('.json')
await update_json.update('D:\home\site\wwwroot\TimerTrigger2\holiday.json',{'name':"jeeva"})
var data2 = await update_json.load('D:\home\site\wwwroot\TimerTrigger2\holiday.json')
context.log(data2.name)
context.log(typeof JSON.stringify(response['data']['data']))
context.log(typeof response['data']['data'])
return response['data']['data']
};
这是我的json文件。
{
"name":"saran"
}
这里我使用的是json-update包,我也同意其他一些包,我该怎么办?
回答如下:您还可以使用“ edit-json-file”包来更新json,我在下面发布了我的代码供您参考:
有关“ edit-json-file”的更多信息,请参见this页面。