-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (22 loc) · 781 Bytes
/
Copy pathserver.js
File metadata and controls
33 lines (22 loc) · 781 Bytes
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
//Server backend file
const express = require('express');
app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static('static_files'));
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://ste519:123@cluster0-9uig7.mongodb.net/test?retryWrites=true";
const client = new MongoClient(uri, { useNewUrlParser: true });
app.get('/feeds', (req, res) => {
console.log("hello");
client.connect((err) => {
const collection = client.db("test").collection("ins");
collection.find({}).toArray((err, result)=>{
if (err) throw err;
else res.send(result);
});
});
});
app.listen(8000, () => {
console.log('Server started at http://localhost:8000/');
});