如何从nodejs中的azure函数更新json文件?

问题描述 投票:0回答:1

我能够从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('https://nseindia.com/live_market/dynaContent/live_watch/stock_watch/nifty500StockWatch.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包,我也同意其他一些包,我该怎么办?

node.js json azure-functions
1个回答
0
投票

您还可以使用“ edit-json-file”包来更新json,我在下面发布了我的代码供您参考:

enter image description here

有关“ edit-json-file”的更多信息,请参见this页面。

© www.soinside.com 2019 - 2024. All rights reserved.