-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (30 loc) · 848 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
36
37
38
39
import express from 'express'
import cors from 'cors'
import morgan from 'morgan'
import connect from './database/conn.js'
import router from './router/router.js'
const app = express()
/**middlewares */
app.use(express.json())
app.use(cors())
app.use(morgan('tiny'))
app.disable('x-powered-by') // less hackers know about our stack
const port = 8080
/**HTTP GET Request */
app.get('/',(req,res)=>{
res.status(201).json('Home GET Request2')
})
/**api routes */
app.use('/api',router)
/**start server only when we have valid connection*/
connect().then(()=>{
try {
app.listen(port,()=>{
console.log(`Server connected to http://localhost:${port}`)
})
} catch (error) {
console.log('Cannot connect to the server');
}
}).catch(error=>{
console.log('Invalid database connection...!');
})