Skip to content

Instantly share code, notes, and snippets.

@aerrity
Created February 21, 2019 17:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aerrity/c71112eb2a66294429a4ddcb6ccef085 to your computer and use it in GitHub Desktop.
Save aerrity/c71112eb2a66294429a4ddcb6ccef085 to your computer and use it in GitHub Desktop.
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