-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (30 loc) · 947 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
40
// Get config
require('dotenv').config()
// Connect to db
require('./services/db')
const express = require('express')
const app = express()
const cors = require('cors')
const logger = require('./middlewares/logger')
const handleErrors = require('./middlewares/handleErrors')
const notFound = require('./middlewares/notFound')
const notesRouter = require('./controllers/notes')
const usersRouter = require('./controllers/users')
// Middlewares
app.use(express.json())
app.use(logger)
app.use(cors())
// Serve images in http://localhost:3001/images/logo.png
app.use('/images', express.static('images'))
// Routes
app.use('/api/notes', notesRouter)
app.use('/api/users', usersRouter)
// Middleware to manage 404
app.use(notFound)
// Middleware to manage errors
app.use(handleErrors)
const PORT = process.env.PORT
const server = app.listen(PORT, () => {
console.log(`Server running on port: ${PORT}`)
})
module.exports = { app, server }