Skip to content

Instantly share code, notes, and snippets.

@rikkrome
Created July 6, 2018 08:21
Show Gist options
  • Save rikkrome/1971564c3b24468912dbe1ba6eb1dc65 to your computer and use it in GitHub Desktop.
Save rikkrome/1971564c3b24468912dbe1ba6eb1dc65 to your computer and use it in GitHub Desktop.
express and mongoDB starting point
// server.js file
const express = require('express');
const mongoose = require('mongoose');
const app = express();
//
// ─── DATABASE ───────────────────────────────────────────────────────────────────
//
// DB Config
const db = require('./config/keys').mongoURI;
// connect to mongoDB
mongoose
.connect(db)
.then(() => {
console.log('MongoDB Connected');
})
.catch(err => {
console.log(err);
console.log('\x1b[31m\x1b[1m MongoDB Not Connected');
});
//
// ─── ROUTES ─────────────────────────────────────────────────────────────────────
//
app.get('/', (req, res) => {
res.send("Hello World");
});
//
// ─── RUN SERVER ─────────────────────────────────────────────────────────────────
//
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`server running on port ${port}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment