-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (25 loc) · 960 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
const express = require('express');
const serverApp = express();
const mongoose = require('mongoose');
require('dotenv').config();
//middleware imports
const bodyParser = require('body-parser');
const logger = require('./middleware/logger');
const notFoundHandler = require('./middleware/notFoundHandler');
const serverErrorHandler = require('./middleware/serverError');
mongoose.connect(process.env.MONGO_URI);
const PORT = process.env.PORT || 5000; //necessary for Heroku deployment
//routers
const productRouter = require('./routers/products');
serverApp.use(bodyParser.json());
serverApp.use(bodyParser.urlencoded({extended: true}));
serverApp.use(logger);
serverApp.use(productRouter); //register the router with the application
serverApp.use(notFoundHandler);
serverApp.use(serverErrorHandler);
serverApp.get('/', (req, res) => {
res.send('HELLO! I work');
})
serverApp.listen(PORT, () => {
console.log(`Now listening on port ${PORT}`);
});