-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 873 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
const express = require('express')
const Datastore = require('nedb');
const app = express()
app.listen(3000, () => console.log('Listening at 3000'));
app.use(express.static('public'));
app.use(express.json({ limit: '1mb' }));
const database = new Datastore('database.db');
database.loadDatabase();
// database.insert({ name: 'Chad', status: 'YES'});
// database.insert({ name: 'Max', status: 'NO'});
app.get('/api', (request, response) => {
database.find({}, (err, data) =>{
if (err){
response.end();
return;
}
response.json(data);
});
});
app.post('/api', (request, response) => {
//console.log('I got a request!');
console.log(request.body);
const data = request.body;
const timestamp = Date.now();
data.timestamp = timestamp;
database.insert(data);
response.json(data);
});