-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (34 loc) · 1.11 KB
/
Copy pathapp.js
File metadata and controls
43 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//Required for MongoDB use
const {MongoClient} = require('mongodb')
const client = new MongoClient("mongodb://127.0.0.1:27017");
//Change these to your collection and database name
const dbName = 'site';
const collectionName = "Song Reviews"
//ExpressJS setup
const express = require('express')
app = express()
//helper methods
const path = require('path')
const bodyParser = require('body-parser')
//Required to take application/json requests
app.use(bodyParser.json());
//Sets up the public asset directory
app.use(express.static(path.join(__dirname,"/public")))
app.use(express.static('public'))
async function dataBaseing(req, res, next){
await client.connect()
let payload = req.body.data
const collection = client.db(dbName).collection(collectionName)
let data = await collection.find(
{"artist" : payload}
).toArray()
res.type('json')
res.send(data)
}
app.get('/', (req,res) =>{res.sendFile("./index.html")})
app.post('/data', dataBaseing, (req, res)=>
{
})
app.listen(8000, ()=>{
console.log('Listening on port 8000')
})