-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
36 lines (27 loc) · 1.29 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import express from 'express';
import bodyParser from 'body-parser';
import path from 'path';
import apiRoutes from './routes';
import mongoose from 'mongoose';
const cors = require('cors');
// Setup Express
const app = express();
app.use(cors());
const port = process.env.PORT || 5000;
// Setup body-parser
app.use(bodyParser.json({ extended: false }));
// Setup our routes. These will be served as first priority.
// Any request to /api will go through these routes.
app.use('/api', apiRoutes);
const MONGODB_URI = 'mongodb+srv://vinny:[email protected]/test?retryWrites=true&w=majority'
// Initialize database. When we quit the server, the db connection will close automatically.
mongoose.connect(MONGODB_URI, { useNewUrlParser: true }).then(
() => console.log('Connected to database!'),
err => console.error(err));
// Make the "public" folder available statically
app.use(express.static(path.join(__dirname, 'public')));
// Start the server running. Once the server is running, the given function will be called, which will
// log a simple message to the server console. Any console.log() statements in your node.js code
// can be seen in the terminal window used to run the server.
app.listen(port, () => console.log(`App server listening on port ${port}!`));
export default app;