-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (33 loc) · 862 Bytes
/
app.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
import express from "express";
import mongoose from "mongoose";
import cors from "cors";
import dotenv from "dotenv";
dotenv.config();
import usersRouter from "./routes/users.js";
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(helmet());
const port = process.env.PORT;
let database = process.env.MONGO_URI;
if (process.env.NODE_ENV === "testing") {
database = process.env.MONGO_URI_TEST;
}
mongoose
.connect(database, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => {
console.log("Database connection established");
})
.catch((err) => {
console.error(`ERROR: ${err}`);
});
app.use("/users", usersRouter);
app.listen(port, () => {
console.log(`Listening on port: ${port}`);
});
export default app;