Created
January 7, 2018 23:36
-
-
Save danthegoodman1/9d7c58f487f67a80c7a596c807c474f7 to your computer and use it in GitHub Desktop.
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
const express = require('express'); | |
const path = require('path'); | |
const bodyParser = require('body-parser'); | |
const cors = require('cors'); | |
const passport = require('passport'); | |
const mongoose = require('mongoose'); | |
const config = require('./config/database'); | |
// Connect to database (this is from the comments since the old .connect() is deprecated) | |
mongoose.createConnection(config.database, {useMongoClient: true}); | |
// Tell us that we connected to the DB | |
mongoose.connection.on('connected', function(){ | |
console.log('connected to database '+config.database); | |
}); | |
mongoose.connection.on('error', function(err){ | |
console.log('Database error: '+err); | |
}); | |
// This is to get rid of the promise deprecation warning: | |
mongoose.Promise = global.Promise; | |
const app = express(); | |
const users = require('./routes/users'); | |
// Port Number | |
const port = 8080 | |
// CORS Middleware | |
app.use(cors()); | |
// Set static folder (to serve website on /) | |
app.use(express.static(path.join(__dirname, 'public'))) | |
// Body Parser Middleware | |
app.use(bodyParser.json()); | |
// Say anything after users is from the /routes/users folder | |
app.use('/users', users); | |
// Index Route | |
app.get('/', function(req, res){ | |
res.send('Invalid endpoint'); | |
}); | |
// Start Server | |
app.listen(port, function(){ | |
console.log('Server started on port: '+ port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment