Skip to content

Commit

Permalink
sorting for 2-7 #35
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman committed May 23, 2019
1 parent ff0d5c5 commit b9b3055
Show file tree
Hide file tree
Showing 8 changed files with 602 additions and 0 deletions.
28 changes: 28 additions & 0 deletions module2/exercise_06_sorting/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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();

app.get('/api', (request, response) => {
database.find({}, (err, data) => {
if (err) {
response.end();
return;
}
response.json(data);
});
});

app.post('/api', (request, response) => {
const data = request.body;
const timestamp = Date.now();
data.timestamp = timestamp;
database.insert(data);
response.json(data);
});
Loading

0 comments on commit b9b3055

Please sign in to comment.