-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (32 loc) · 1018 Bytes
/
server.js
File metadata and controls
41 lines (32 loc) · 1018 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
37
38
39
40
41
require('dotenv').config();
const express = require("express");
const mongoose = require("mongoose");
const routes = require("./routes");
const app = express();
const PORT = process.env.REACT_APP_PORT || 3001;
//console.log("REACT_APP_MONGODB_URI: "+process.env.REACT_APP_MONGODB_URI);
//console.log("REACT_APP_PORT: "+process.env.REACT_APP_PORT);
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.use(routes);
//Mongo DB connection
mongoose.connect(
process.env.REACT_APP_MONGODB_URI || "mongodb://localhost/google",
{
// useCreateIndex: true,
useNewUrlParser: true
}
);
mongoose.set('strictQuery', true);
mongoose.connection
.once("open", () => console.log("MongoDB connected"))
.on("error", error => {
console.log("MongoDB error: ", error);
});
// Start the API server
app.listen(PORT, () =>
console.log(`🌎 ==> API Server now listening on PORT ${PORT}!`)
);