-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (27 loc) · 940 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
32
33
const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const morgan = require('morgan');
const mongoose = require('mongoose');
const routes = require("./router/api");
const app = express();
const PORT = process.env.PORT || 4000;
app.use(cors());
app.use(bodyParser.json());
const MONGODB_URI = "mongodb+srv://jannat:[email protected]/<dbname>?retryWrites=true&w=majority"
console.log(process.env.MONGODB_URI);
mongoose.connect(process.env.MONGODB_URI || MONGODB_URI || 'mongodb://127.0.0.1:27017/blogPosts', {
useNewUrlParser: true,
useUnifiedTopology: true
});
mongoose.connection.on('connected', () => {
console.log('Mongoose connected');
})
app.use(morgan('tiny'));
app.use('/', routes);
if(process.env.NODE_ENV == "production"){
app.use(express.static("client/build"))
}
app.listen(PORT, () => {
console.log(`Listening at port ${PORT}`)
})