-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (25 loc) · 819 Bytes
/
index.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
import express from 'express';
import db from './db/database.js';
import bodyparser from 'body-parser';
import UserRoutes from './controller/users.controller.js';
const app = express();
const port = 5000;
// middleware
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ extended: true }));
app.use('/api/users', UserRoutes);
app.use((err,req,res,next)=>{
console.log(err);
res.status(err.status || 500).send("something went wrong!")
})
//db connection
db.query("SELECT 1")
.then(() => {
console.log(`db connection success`)
//this is where we listen after db connection is successful
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
})
})
.catch(err => console.log(`db connection failed \n ${err}`));
export default app;