-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (28 loc) · 817 Bytes
/
index.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
require("dotenv").config();
const express = require('express');
const cors = require('cors');
const connectDB = require("./config/db");
const router = require("./routes/users");
const errorHandler = require("./middleware/error");
connectDB();
const port = process.env.PORT || 5000;
const app = express();
//middlewares
app.use(cors({
origin:'*'
}));
app.use(express.json())
app.use("/api/users", router);
app.use("/",(req,res)=>{
return res.json({
message: "Welcome to the node.js REST API using ExpressJS and MongoDB",
})
});
app.use(errorHandler);
const server = app.listen(port,()=>{
console.log(`Server is listening on port ${port}`)
})
process.on("unhandledRejection",(error,promise)=>{
console.log(`Logged Error : ${error}`);
server.close(()=> process.exit(1));
})