Created
February 21, 2019 17:08
-
-
Save aerrity/c71112eb2a66294429a4ddcb6ccef085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const MongoClient = require('mongodb').MongoClient; | |
const server = express(); | |
const port = 3000; | |
server.get('/', (req, res) => res.send('Hello World!')); | |
server.get('/api/users', (req, res) => { | |
MongoClient.connect('mongodb://localhost:27017/REACTCA2', function (err, client) { | |
if (err) throw err | |
const db = client.db('REACTCA2') | |
db.collection('Users').find().toArray(function (err, result) { | |
if (err) throw err | |
res.send(result); | |
}) | |
}) | |
}); | |
server.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment