-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
25 lines (17 loc) · 752 Bytes
/
server.js
File metadata and controls
25 lines (17 loc) · 752 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
const express = require("express");
const connectDb = require("./config/dbConnections")
const errorHandler = require("./middleware/errorHandler");
const dotenv = require("dotenv").config();
// Connection with mongodb before creating my express app
connectDb();
const app = express();
const port = process.env.PORT || 5000;
// Whenever I need to use a middleware , we must use app.use()
// Whenever we use /api/contacts route, it use the contactRoutes request and response
// app.use is for middleware
app.use(express.json()) // Provides a parser to read JSON data in the body of requests
app.use("/api/users" , require("./routes/userRoutes"))
app.use(errorHandler)
app.listen(port , () => {
console.log(`Server running on port ${port}`)
})