-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 789 Bytes
/
index.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 express = require('express');
const app = express();
const Datastore = require('nedb');
const database = new Datastore('database.db');
const timestamp = Date.now();
app.listen(3000, () => console.log('Listening at 3000'));
app.use(express.static('public'));
app.use(express.json({
limit: '1mb'
}));
database.loadDatabase();
app.get('/api', (request, response) => {
const data = database.find(request.body);
response.json(data);
});
app.post('/api', (request, response) => {
console.log(request.body);
const data = request.body;
data.timestamp = timestamp;
database.insert(data);
response.json({
mood: data.mood,
status: 'success',
latitute: data.lat,
longitute: data.lon,
timestamp: timestamp
});
});