-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (23 loc) · 812 Bytes
/
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
require('dotenv').config();
var express = require('express');
const cors = require('cors');
var app = express();
const PORT = 5000;
app.use(cors());
app.use(express.json());
var mongoose = require('mongoose');
var mongoDB = process.env.DATABASE_URL;
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
const db = mongoose.connection;
db.once('open', () => {
console.log('MongoDB connection established successfully');
});
const postsRouter = require('./backend/routes/posts');
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
app.use('/posts', postsRouter);
app.use(function(req, res, next) {
res.status(404).send("Sorry, that route doesn't exist.")
});
app.listen(PORT, function() {
console.log(`Protor is listening on Port ${PORT}`);
});