Skip to content

Commit

Permalink
drawings 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 96d2b66 commit 61c93d2
Show file tree
Hide file tree
Showing 10 changed files with 592 additions and 2 deletions.
3 changes: 1 addition & 2 deletions module2/exercise_07_save_files/shiffman.db
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{"lat":40.7296086,"lon":-73.9938007,"mood":"rainbow","image_file":"image_1558376232234.png","timestamp":1558376232234,"_id":"7QLBKrUrXTPAoEyA"}
{"lat":40.7296086,"lon":-73.9938007,"mood":"unicorn","image_file":"image_1558376240358.png","timestamp":1558376240358,"_id":"rLp45mGTbW4wa5pw"}
{"lat":40.7296086,"lon":-73.9938007,"mood":"🚂🌈","image_file":"image_1558376266448.png","timestamp":1558376266448,"_id":"YLHImEEXOlLOPbFJ"}
{"lat":40.7296086,"lon":-73.9938007,"mood":"❤️❤️❤️❤️❤️❤️❤️","image_file":"image_1558376281197.png","timestamp":1558376281197,"_id":"j2knqdvxHKqC2EB8"}
`
{"lat":40.7296086,"lon":-73.9938007,"mood":"❤️❤️❤️❤️❤️❤️❤️","image_file":"image_1558376281197.png","timestamp":1558376281197,"_id":"j2knqdvxHKqC2EB8"}
3 changes: 3 additions & 0 deletions module2/exercise_08_p5_drawings/drawings.db

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions module2/exercise_08_p5_drawings/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 61c93d2

Please sign in to comment.