-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (26 loc) · 898 Bytes
/
app.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
const { json } = require('express')
const express = require('express')
const { connectDB } = require('../logs-project/connect')
const { errorHandler } = require('../logs-project/middleware/error-handler')
const { notFound } = require('../logs-project/middleware/not-found')
const {router} = require('./route')
require('dotenv').config()
require('express-async-errors')
const app = express()
const port = process.env.PORT || 3000
async function start(){
try{
await connectDB(process.env.mongo2_uri)
console.log('connected to the DB')
app.listen(port, console.log(`server is listening on port ${port} `))
}catch(error){
console.log(error)
}
}
start()
app.use(express.json())
app.use('/api/products', router)
app.use(errorHandler)
app.get('/', (req,res)=>{
res.status(200).send('<h1>Homepage</h1><a href="/api/products" >Products</a>')
})