-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 911 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
30
31
32
33
34
35
36
37
38
39
// require dotenv module so we can use environment variables
require('dotenv').config();
const express=require('express');
const morgan = require('morgan');
const { connectDB } = require('./config/db.config');
const app=express();
const createError=require('http-errors');
// check if there's already a port on the environment, otherwise use port 3300;
const port=process.env.PORT ||3300;
// connect to the database
connectDB();
const quotesRouter=require('./routes/quotes.route');
// set up middlewares
// accept JSON
app.use(express.json())
// accept form
app.use(express.urlencoded({
extended:false
}));
// log api info
app.use(morgan('dev'));
app.get('/',(req,res)=>{
res.send('hello quotes api')
});
// set up routes
app.use('/quotes',quotesRouter);
app.use((req,res,next)=>{
return next(createError(404))
})
app.listen(port,()=>{
console.log(`server listening on port ${port}`)
})