-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
53 lines (42 loc) · 1.44 KB
/
script.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const
express = require('express'),
app = express(),
fs = require('fs'),
shell = require('shelljs'),
bodyParser = require('body-parser'),
path = require('path');
const
defaultFileExtension = 'json'; // Change the default file extension
var datetime = new Date();
const
folderPath = path.join('./', datetime.toISOString().slice(0,10), '/');
// process.exit();
// Create the folder path in case it doesn't exist
shell.mkdir('-p', folderPath);
// Change the limits according to your response size
app.use(bodyParser.json({limit: '50mb', extended: true}));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true, type: 'application/vnd.ms-excel' }));
app.get('/', (req, res) => res.send('Hello, I am pauluZ !'));
app.get('/testing', (req, res) => {
console.log('requestName: ' + req);
var dt = new Date();
res.send('Date: ' + dt.toISOString());
});
app.post('/write', (req, res) => {
let extension = req.body.fileExtension || defaultFileExtension,
filePath = `${path.join(folderPath, req.body.requestName)}.${extension}`;
fs.writeFile(filePath, req.body.responseData, (err) => {
if (err) {
console.log(err);
res.send('Error');
}
else {
console.log('filePath: ' + filePath);
res.send('Success');
}
});
});
app.listen(3000, () => {
console.log('ResponsesToFile App is listening now!');
console.log(`${path.join(process.cwd(), folderPath)}`);
});