Example DB

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2021-07-26 09:55:13 +05:30
commit 406c23244c
3 changed files with 52 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules/*
node_modules/
package-lock.json

33
app.js Normal file
View File

@ -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}`)
})

16
package.json Normal file
View File

@ -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"
}
}