-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
34 lines (28 loc) · 817 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
34
// dendencies
const express = require("express");
const mongoose = require("mongoose");
const routes = require("./routes");
const passport = require("./authentication/passport");
// setup the port and the express app
const PORT = process.env.PORT || 4000;
const app = express();
// setup the mongodb database
mongoose.connect(
process.env.MONGODB_URI || "mongodb://localhost/passportJwtExample",
{
useNewUrlParser: true,
useUnifiedTopology: true,
}
);
// middlewares for accepting post requests
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
// routes
app.use("/", routes);
// start the server
app.listen(PORT, () => {
console.log(`You're being served on port ${PORT}!!!`);
});