const express = require('express'); const bodyParser = require('body-parser'); const low = require('lowdb'); const FileAsync = require('lowdb/adapters/FileAsync'); const app = express(); // app is an instance of express app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded app.use(bodyParser.json()) // parse application/json app.use(express.static(__dirname + '/build')); // serve static build site app.post('/test',(req,res)=>{ res.send(req.body); }) // Create database instance and start server // const adapter = new FileAsync(__dirname + '/db.json'); low(new FileAsync(__dirname + '/db.json')) .then(db => { // DATABASE ROUTES // GET /videolog app.get('/videolog', (req, res) => { const post = db .get('videos') // .find({ id: req.params.id }) .value(); res.send(post); }); // POST /videolog app.post('/videolog', (req, res) => { db.get('videos') .push(req.body) .last() .update('timesWatched', n => n + 1 ) .write() .then(post => res.send(post)); // non funziona minimamente lol }); // Set db default values return db .defaults({ videos: [ // { // videoId: '', // timesWatched: 0, // prevalentReason: '', // lastSelected: new Date() // } ] }) .write(); }) .then(() => { app.listen(8000, () => console.log('listen on 8000')); // bind to port 8000 as required from specs });