Created
July 6, 2018 08:21
-
-
Save rikkrome/1971564c3b24468912dbe1ba6eb1dc65 to your computer and use it in GitHub Desktop.
express and mongoDB starting point
This file contains hidden or 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
// 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