Skip to content

Commit d2d5b4d

Browse files
author
Sivcan Singh
committed
Initial commit
0 parents  commit d2d5b4d

File tree

5 files changed

+582
-0
lines changed

5 files changed

+582
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
responses

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ResponseToFile-Postman
2+
3+
This project will help in writing the responses of a request from Postman

app.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const express = require('express');
2+
app = express();
3+
fs = require('fs');
4+
shell = require('shelljs');
5+
folderPath = './responses/'; // Modify the folder path in which responses need to be stored
6+
fileExtension = '.json'; // Change the file extension
7+
bodyParser = require('body-parser'),
8+
path = require('path');
9+
10+
shell.mkdir('-p', folderPath);
11+
12+
app.use(bodyParser.json({limit: '50mb', extended: true})); // Change limit according to your response size
13+
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true })); // Change limit accordingly
14+
15+
app.get('/', (req, res) => res.send('Hello, I write data to file.'));
16+
17+
app.post('/write', (req, res) => {
18+
let filePath = `${path.join(folderPath, req.body.requestName)}${fileExtension}`;
19+
fs.writeFile(filePath, req.body.responseData, (err) => {
20+
if (err) {
21+
console.log(err);
22+
res.send('Error');
23+
}
24+
else {
25+
res.send('Success');
26+
}
27+
});
28+
});
29+
30+
app.listen(3000, () => console.log('Postman-File App listening on port 3000!'))

0 commit comments

Comments
 (0)