-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
37 lines (30 loc) · 790 Bytes
/
index.js
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
const express = require('express');
const app = express();
const mongodb = require('mongodb');
const config = {
DB: 'mongodb://mongo:27017'
};
const PORT = 3000;
const client = mongodb.MongoClient;
var dbo;
client.connect(config.DB, function(err, db) {
if(err) {
console.log('database is not connected')
}
else {
console.log('connected!!');
dbo = db.db("midb");
}
});
app.get('/', function(req, res) {
res.json({"hello": "express with mongo"});
});
app.get('/misdatos', function(req, res){
let data = dbo.collection("micoleccion").find({}).toArray((err, result) => {
if (err) throw err;
res.json(result);
});
});
app.listen(PORT, function(){
console.log('Your node js server is running on PORT:',PORT);
});