-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (37 loc) · 1.11 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
44
45
46
const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const app = express();
const cors = require("cors");
//Import Models
require("./models/User");
require("./models/Company");
// require('./models/Invitation');
//Enable CORS policy
app.use(cors());
app.options("*", cors());
//Access to .env file (use for save global variables - UNMODIFED)
dotenv.config();
const mongoUri = process.env.DATABASE_ACCESS;
//Mongo DB - Connection
mongoose.connect(mongoUri, {
useUnifiedTopology: true,
useNewUrlParser: true,
});
mongoose.connection.on("connected", () => {
console.log("Connected to mongoDB instance");
});
mongoose.connection.on("error", (err) => {
console.error("Error with connecting to mongo", err);
});
//Body - Parser
app.use(express.json());
//Routes
const userRoutes = require("./routes/userRoute");
const companyRoutes = require("./routes/companyRoute");
//Routes Relative to the first argument string
app.use("/users", userRoutes);
app.use("/companies", companyRoutes);
app.listen(4000, () => {
console.log("Server is up and listening on port 4000");
});