forked from bezkoder/node-express-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (34 loc) · 1.07 KB
/
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
35
36
37
38
39
40
41
42
43
const express = require("express");
// const bodyParser = require("body-parser"); /* deprecated */
const cors = require("cors");
const app = express();
var corsOptions = {
origin: "http://localhost:8082",
};
app.use(cors(corsOptions));
// parse requests of content-type - application/json
app.use(express.json()); /* bodyParser.json() is deprecated */
// parse requests of content-type - application/x-www-form-urlencoded
app.use(
express.urlencoded({ extended: true })
); /* bodyParser.urlencoded() is deprecated */
const db = require("./app/models");
db.mongoose
.connect(db.url, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Connected to the database!");
})
.catch((err) => {
console.log("Cannot connect to the database!", err);
process.exit();
});
app.use("/api/user",require("./app/routes/api/user"));
app.use("/api/prices",require("./app/routes/api/prices"));
// set port, listen for requests
const PORT = process.env.PORT || 8082;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});