您好,我想根据某些条件进行多个发布请求。我正在尝试,但是我的代码无法正常工作。我有一个在线存储的数据库(Firebase)。我要做的是从在线获取数据并保存到localdb,然后删除在线数据。

这是我到目前为止所做的

request('http://my-url here', function (error, response, body) {
    console.log('error:', error);
    console.log('statusCode:', response && response.statusCode); Print the response status code if a response was received

    var data = [];
    var parse = JSON.parse(body);

    var ids =  Object.keys(parse);
     var i = 0;

   ids.forEach(function(id) {
   var unique_keys =  Object.keys(parse[id]);
        unique_keys.forEach(function(unique_key) {

            data[i] = [

                    parse[id][unique_key]["lat"],
                    parse[id][unique_key]["long"],



                ];
                i++;
   });

 });

    saveHistory(data, function (result) {

        console.log("successfully save into local db");
        removeDataFromOnlineDatabase
        process.exit();

    });





});

function removeHistoryFromOnlineDatabase(){

    var request = require("request");

   console.log("function get called");
    var options = { method: 'DELETE',
        url: 'url here',
        headers:
            { 'Postman-Token': '4a126ab8-9b3e-465d-b827-d4dd83923610',
                'Cache-Control': 'no-cache',
                'Content-Type': 'application/json' } };

    request(options, function (error, response, body) {
        if (error) throw new Error(error);

        console.log("history has been removed" + body);
    });

}


我已经尝试了上面的代码,但是此功能removeHistoryFromOnlineDatabase发布请求不起作用

函数被调用并显示“函数被调用”,但不显示“历史记录已被删除”

最佳答案

process.exit();移到console.log("history has been removed" + body);

10-06 15:35