-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (28 loc) · 953 Bytes
/
Copy pathserver.js
File metadata and controls
36 lines (28 loc) · 953 Bytes
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
const path = require('path');
const logger = require('morgan');
const bodyParser = require('body-parser');
const express = require('express');
const app = express();
const mongoose = require("mongoose");
const cors = require('cors');
const routes = require("./server/routes");
// app.use(logger('dev'));
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static("client/build"));
app.use("/", routes);
const configDB = require('./server/config/database');
mongoose.Promise = global.Promise;
mongoose.connect(configDB.url);
const db = mongoose.connection;
db.on('error', function(err) {
console.log('MongoDB connection error:', err);
});
db.once("open", function() {
console.log("Mongoose connected to version", mongoose.version);
});
const PORT = process.env.PORT || 3001;
app.listen(PORT, function() {
console.log(`🌎 ==> API server listening on PORT ${PORT}!`);
});