-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (24 loc) · 765 Bytes
/
server.js
File metadata and controls
30 lines (24 loc) · 765 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
const express = require("express");
const app = express();
const dotenv = require("dotenv").config();
const contactsRouter = require("./router/contacts");
const usersRouter = require("./router/users");
const errorHandler = require("./middlewares/errorHander");
const connectDB = require("./database/connectDB");
const port = process.env.PORT || 3000;
app.use(express.json());
app.use("/api/v1/contacts", contactsRouter);
app.use("/api/v1", usersRouter);
// Always add errorHandler at the bottom of the other middlewares
app.use(errorHandler);
const start = async () => {
try {
await connectDB();
app.listen(port, () =>
console.log(`---- Server is listening on port ${port}!`)
);
} catch (error) {
console.log(error);
}
};
start();