-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (26 loc) · 753 Bytes
/
server.js
File metadata and controls
36 lines (26 loc) · 753 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
// importing express
const express = require('express');
// importing db
const db = require('./db/database');
// port destination
const PORT = process.env.PORT || 3001;
// app expression
const app = express();
// importing apiRoutes folder
const apiRoutes = require('./routes/apiRoutes');
// express middleware
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
// use apiRoutes
app.use('/api', apiRoutes);
// default response for any other request (Not Found) Catch all
app.use((req, res) => {
res.status(404).end();
});
// start server after DB connection
db.on('open', () => {
// listen function
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
});