-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (29 loc) · 943 Bytes
/
server.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
const fs = require('fs');
const cors = require('cors');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 5000;
app.use(cors());
app.use(bodyParser.json());
app.listen(port, () => console.log(`Listening on port ${port}`));
app.get('/customer-data', (req, res) => {
fs.readFile('./customer-data.json', (err, data) => {
if (err) {
res.status(500).send('Internal service error');
} else {
const data = fs.readFileSync('./customer-data.json');
res.send(data);
}
});
});
app.post('/customer-data', (req, res) => {
const data = JSON.stringify(req.body);
fs.writeFile('./customer-data.json', data, (err) => {
if (err) {
res.status(500).send('Internal service error');
} else {
res.json({ message: 'Customers updated' });
}
});
});