0

i am writing a program that send multiple request ti retrieve some data from an external api , it works fine , but when i try to add a function "appendFile" that save the data received in a json the server starts to behave strangely and restart every time ,and resend the same request again and again which wasn't thes case before i added the function , if you have any insights abozt this problem please help , thanks : enter image description here here is my code to send request and and save the data in a json

const streamActivity = (client) => (activityId) => {
    return new Promise((resolve, reject) => {
        client.streams.activity(
            {
                id: activityId,
                types:
                    "time,heartrate,velocity_smooth,altitude,distance,latlng,cadence,watts,temp,moving,grade_smooth,average_speed",
                resolution: "high",
            },
             function (err, payload,next) {

                    if (!err ) {



                    //save to json
              appendToFile1('activity-streams.json', payload)


                    



                } else {
                   reject(err)
                }
            }
        );
    });
     // setInterval(streamActivity,5000);

};

and this is the append file function :

function appendToFile1(file, payload) {
    fs.appendFile(file, JSON.stringify({payload}), (err) => {
        if (err) throw err
        console.log('Done writing') // Success
    })
}
justLearning
  • 59
  • 1
  • 7
  • Are there any errors before the restart? In your Promise body you don't call `resolve` executor. That might be the case. – Viktor Gusev Jul 09 '21 at 10:55
  • no there are no errors ever , ihave added a photo for the console log please chach it – justLearning Jul 09 '21 at 11:15
  • See this - https://stackoverflow.com/questions/44855839/nodemon-keeps-restarting-server . File you write payload into triggers nodemon to restart. – Viktor Gusev Jul 09 '21 at 12:00

0 Answers0