-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (33 loc) · 1021 Bytes
/
server.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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const authRoute = require("./routes/auth");
const jobRoute = require("./routes/job");
const cors = require('cors')
const app = express();
app.use(cors())
app.use(express.json());
mongoose
.connect(process.env.MONGODB_URL)
.then(() => console.log("DB Connected!"))
.catch((error) => console.log("DB failed to connect", error));
app.get("/api/health", (req, res) => {
res.json({
service: "Backend Joblisting server",
status: "active",
time: new Date(),
});
});
app.use("/api/v1/auth", authRoute);
app.use("/api/v1/job", jobRoute);
app.use("*", (req, res) => {
res.status(404).json({ errorMessage: "Route not found!" });
});
app.use((error, req, res, next) => {
console.log(error);
res.status(500).json({ errorMessage: "Something went wrong!" });
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Backend server running at port ${PORT}`);
});