# Export test result to a file

**URL:** <https://community.postman.com/t/export-test-result-to-a-file/17730>\
**Category:** Help Hub\
**Created:** [November 16, 2020, 12:20pm UTC](https://community.postman.com/t/export-test-result-to-a-file/17730 "2020-11-16T12:20:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ereddy068](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ereddy068](https://community.postman.com/u/ereddy068)\
**Post date:** [November 16, 2020, 12:20pm UTC](https://community.postman.com/t/export-test-result-to-a-file/17730/1 "2020-11-16T12:20:49Z")

</div>

I have written a test and now I need to export the result to a file in my local disk.

I need to do that in the code itself. COuld anyone tell me how I can do that.

I need to save the respone c in a file

 ![Screenshot 2020-11-16 131904](https://us1.discourse-cdn.com/getpostman/original/3X/9/4/94e8c48ad1aa59d8dbced08d20813dba6324595c.jpeg)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [November 16, 2020, 1:33pm UTC](https://community.postman.com/t/export-test-result-to-a-file/17730/2 "2020-11-16T13:33:41Z")

</div>

Hello @ereddy068 🙂

To do this action via code as you mentioned, then you would need Newman to do along. How are you running your Tests? Through collection runner or via Newman? Please share more details here.

Also please check the similar query raised and see if it helps.

> [@Save response in CSV file via newman](https://community.postman.com/t/save-response-in-csv-file-via-newman/15508/12):
>
> ahh yes, already have it like this [image] [image] also have newman-reporter-csv package inside the node\_modules

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [November 19, 2020, 9:04pm UTC](https://community.postman.com/t/export-test-result-to-a-file/17730/3 "2020-11-19T21:04:57Z")

</div>

If you are running through a collection runner, then first need to check Save response. After it got executed. You can export the result  
for newman you need use [newman library](https://github.com/DannyDainton/newman-reporter-htmlextra#with-newman-as-a-library) run you need to use your paths

```auto
const newman = require('newman'),
      fs = require('fs')

newman.run({
  collection: '<Collection File>',
  environment: '<env path json file',
  iterationCount: 1

}).on('console', function (error, args) {
      fs.appendFileSync('./results.csv', args.messages, function (error) {
  })
})

```
