-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.js
35 lines (25 loc) · 862 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
var express = require('express');
var fs = require('fs');
// Create the app
var app = express();
// Set up the server
// process.env.PORT is related to deploying on heroku
var server = app.listen(process.env.PORT || 3000, listen);
// This call back just tells us that the server has started
function listen() {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://' + host + ':' + port);
}
// this is the API to accept JSON files
app.use(express.json({limit: '2mb'}));
app.post('/', function(request, response){
console.log(request.body); // your JSON
response.send(request.body);
var mydata = JSON.stringify(request.body, null, 2);
var reply = fs.writeFile('mydata.json', mydata, finished);
function finished() {
console.log('all set')
};
response.send(reply);
});