Skip to content

Commit 6e6d46c

Browse files
author
Andrew Switlyk
committed
on get request to comments.json, update variable comments (from filesystem read) before sending stringified comments in response.
1 parent c6c8f1f commit 6e6d46c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ app.use(bodyParser.json());
2323
app.use(bodyParser.urlencoded({extended: true}));
2424

2525
app.get('/comments.json', function(req, res) {
26+
comments = JSON.parse(fs.readFileSync('_comments.json'));
2627
res.setHeader('Content-Type', 'application/json');
2728
res.send(JSON.stringify(comments));
28-
comments = JSON.parse(fs.readFileSync('_comments.json'));
2929
});
3030

3131
app.post('/comments.json', function(req, res) {
3232
comments.push(req.body);
33-
fs.writeFile('_comments.json', JSON.stringify(comments))
33+
fs.writeFile('_comments.json', JSON.stringify(comments));
3434
res.setHeader('Content-Type', 'application/json');
3535
res.send(JSON.stringify(comments));
3636
});

0 commit comments

Comments
 (0)