-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (33 loc) · 980 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
40
// Imports
const express = require('express');
const path = require('path');
const cors = require('cors');
const dotenv = require('dotenv');
const mongoose = require('mongoose');
dotenv.config();
// Connect to DB
mongoose
.connect(process.env.DB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
})
.then(console.log('Connected to db'))
.catch(e =>
console.log('Error trying to connect to the database: ', e.message),
);
// Load Routes
//const indexRouter = require('./routes/index');
const apiRouter = require('./routes/api');
// Initialize
const app = express();
app.use(express.json());
app.use(cors());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
// initialize routes
//app.use('/.netlify/functions/', indexRouter);
app.use('/api', apiRouter);
// Run server
const PORT = process.env.PORT || 8000;
app.listen(PORT, console.log(`Server listening on port: ${PORT}`));