Example DB
This commit is contained in:
commit
406c23244c
|
@ -0,0 +1,3 @@
|
|||
node_modules/*
|
||||
node_modules/
|
||||
package-lock.json
|
|
@ -0,0 +1,33 @@
|
|||
const BaseDB = require('dbd.db')
|
||||
const DB = BaseDB('database')
|
||||
const Collection = DB.collection({
|
||||
name: "Collection",
|
||||
ttl: 5 //optional
|
||||
})
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
const port = 3000
|
||||
|
||||
app.get('/add/:opinion', (req, res) => {
|
||||
var id = new Date().getTime();
|
||||
var timestamp = new Date().toISOString();
|
||||
var opinion = req.params.opinion
|
||||
console.log(opinion, timestamp)
|
||||
// console.log(req.params.opinion);
|
||||
;(async () => {
|
||||
await Collection.set({
|
||||
id: id,
|
||||
timestamp: timestamp,
|
||||
opinion: opinion
|
||||
})
|
||||
|
||||
console.log(await Collection.find({
|
||||
opinion: "Hi"
|
||||
}))
|
||||
})()
|
||||
res.send('Hello World!')
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`API listening at http://localhost:${port}`)
|
||||
})
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "jsondb",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node app.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"cookie-parser": "~1.4.4",
|
||||
"dbd.db": "^1.4.5",
|
||||
"debug": "~2.6.9",
|
||||
"express": "~4.16.1",
|
||||
"lowdb": "^2.1.0",
|
||||
"morgan": "~1.9.1"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue