-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave-response.js
More file actions
38 lines (33 loc) · 916 Bytes
/
save-response.js
File metadata and controls
38 lines (33 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require("fs");
const newman = require("newman");
// Set your postman collection.
const collection = require("./sample-collection.json");
const newmanOptions = {
collection,
reporters: "cli",
iterationData: "./TEST_DATA.csv", // Set the iteration data in the collection
};
newman.run(newmanOptions).on("request", (error, data) => {
if (error) {
console.log(error);
} else {
if (data.response.stream) {
const responseData = data.response.stream.toString();
// Append data to the CSV file for each request
fs.appendFileSync("response.csv", `${responseData}\n`, function (error) {
if (error) {
console.log(error);
}
});
fs.writeFileSync(
"response.txt",
data.response.stream.toString(),
function (error) {
if (error) {
console.log(error);
}
}
);
}
}
});