-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (23 loc) · 772 Bytes
/
app.js
File metadata and controls
36 lines (23 loc) · 772 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
const express = require('express');
// load environment variables
require('dotenv').config();
const orderRoutes = require('./routes/order');
const app = express();
// your app global middlewares
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// routing your http requests
app.use('/api', orderRoutes);
// `Not Found` request handler
app.use((req, res, next) => {
const error = new Error('Not Found');
error.status = 404;
throw error;
});
// thrown erros handler
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({ message: error.message || 'Internal Server Error' });
});
// bootstrap your server
app.listen(process.env.PORT, () => console.log('Server running on port ' + process.env.PORT));