-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (32 loc) · 860 Bytes
/
server.js
File metadata and controls
36 lines (32 loc) · 860 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
31
32
33
34
35
36
import express from "express";
import cors from "cors";
import clientRoutes from "./routes/client.routes.js";
import morgan from "morgan";
import dotEnv from "dotenv";
import { connection } from "./db/connection.js";
// import chalk from "chalk";
// import path from "path";
dotEnv.config();
// Connect To mongoose
connection();
// Setting up middleware
const app = express();
app.use(cors());
app.use(morgan("tiny"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/api", clientRoutes);
// server listen
const port = process.env.PORT || 5000;
const server = app.listen(port, () =>
console.log(`Server is Running on ${port}`)
);
// error handler middleware
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500).send({
status: 500,
message: err.message,
body: {},
});
});