How to copy all the responses from postman into a file

I have a curl command which i am running in postman, i pass a variable with 2 values and i am using the “Write Responses To File” method to get the output in a json file. However when i run my code in collection runner the 2 value data gets override by the 1 value data. Can someone help me with how to not override the data in the file and keep appending to the existing? Below is the code i have in my tests where its generating the file

// The opts for the server, also includes the data to be written to file

let opts = {

requestName: request.name || request.url,

fileExtension: 'json',

mode: 'writeFile', // Change this to any function of the fs library of node to use it.

uniqueIdentifier: 'waddup',

responseData: pm.response.text()

};

pm.sendRequest({

url: 'http://localhost:3000/write',

method: 'POST',

header: 'Content-Type:application/json',

body: {

    mode: 'raw',

    raw: JSON.stringify(opts)

}

}, function (err, res) {

console.log(res);

});

Hi @sujithkumar.matharas,

Welcome to the Community :wave:.

As noted here:
mode: 'writeFile', // Change this to any function of the fs library of node to use it.

You should be able to change this to any function of the fs library of node. Have you tried appendFile instead?

https://nodejs.org/api/fs.html#fs_fs_appendfile_path_data_options_callback

1 Like

Thanks a lot Sabri, as i am new to this i didnt knew that. That is what exactly what i was looking for. Thank you for your help.