Skip to content

Instantly share code, notes, and snippets.

@vinnyoodles
Created February 6, 2018 17:44
Show Gist options
  • Save vinnyoodles/ed5570261132e40314e0815d8e445eba to your computer and use it in GitHub Desktop.
Save vinnyoodles/ed5570261132e40314e0815d8e445eba to your computer and use it in GitHub Desktop.
sample express server with mongodb
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