-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
45 lines (32 loc) · 934 Bytes
/
Copy pathserver.js
File metadata and controls
45 lines (32 loc) · 934 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
37
38
39
40
41
42
const express = require('express')
const app = express();
const path = require('path')
require('dotenv').config()
//middlewares
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
//requiring config
const mongo_connection = require(path.join(__dirname, 'config', 'db'))
//requiring routes
const ProductRoute = require(path.join(__dirname, 'routes', 'products.route'))
//Product Route
app.use('/products', ProductRoute)
// 404 Handling
app.use((req, res, next) => {
const error = new Error('Not Found')
error.status = 404
next(error)
})
//error handling
app.use((err, req, res, next) => {
res.status(err.status || 500)
res.send({
error: {
status: err.status || 500,
message: err.message || 'Internal Server Error'
}
})
})
app.listen(process.env.PORT, () => {
console.log(`Your Application is running on PORT ${process.env.PORT}`);
})