Created
February 6, 2018 17:44
-
-
Save vinnyoodles/ed5570261132e40314e0815d8e445eba to your computer and use it in GitHub Desktop.
sample express server with mongodb
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
var express = require('express'); | |
var mongojs = require('mongojs'); | |
var db = mongojs(process.env.MONGO_URL || 'mongodb://localhost:27017/local'); | |
var app = express(); | |
app.use('/public', express.static('public')) | |
app.listen(3000, () => console.log('listening on *:3000')); | |
// Endpoints | |
app.get('/', (req, res) => res.send('Hello World!')) | |
app.get('/foo', (req, res) => { | |
db.collection('users').find({}, (err, results) => { | |
res.send({err, results}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment