-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (23 loc) · 871 Bytes
/
Copy pathserver.js
File metadata and controls
28 lines (23 loc) · 871 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
require("dotenv").config();
const db = require("./models/db"); // db connection/refused connection
const express = require("express");
const userRoute = require("./routes/user");
const router = express(); //ask for router to express
const port = process.env.PORT || 3000; // Use port from .env or default to 3000
router.listen(port, () => {
console.log("Express server started on port : 3000");
});
router.use(express.urlencoded({ extended: true }));
router.use(express.json());
router.get("/", function (req, res) {
res.send("api working");
});
router.use("/userRoute", userRoute);
// Error handling if passed request doesnt matched with anything
router.use((req, res, next) => {
const error = new Error(
"EndPoint does not exist...Please check our requested URL"
);
console.log(error);
return res.status(404).json({ message: error.message });
});