-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (28 loc) · 830 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
// dependencies
import express from "express";
import { APP_PORT, DB_URL } from "./config";
import routes from "./routes";
import errorHandler from "./middleware/errorHandler";
import mongoose from "mongoose";
import path from "path";
// app object
const app = express();
// global
global.appRoote = path.resolve(__dirname);
// database connection
mongoose
.connect(DB_URL, {})
.then(() => console.log(`Connect Successful`))
.catch((err) => console.log(err));
// Application Middlware
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Routes Middleware
app.use("/api", routes);
app.use("/uploads",express.static('uploads'))
// Error Handling Middleware
app.use(errorHandler);
// listening server
app.listen(APP_PORT, () =>
console.log(`Server start on: http://localhost:${APP_PORT}`)
);