-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (40 loc) · 1 KB
/
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
41
42
43
44
45
46
47
// Imports
require('dotenv').config();
const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
const jwt = require('jsonwebtoken');
const bcrypt = require('bcrypt');
const app = express(); // Creates express server instance
// Import project dirs
const { apiRouter } = require('./api/index');
const { client } = require('./db/Index');
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(morgan('dev'));
app.use(cors());
// Catch-all route handler
app.get("/", (req, res) => {
res.send("Server is Running!")
});
// Router Handelers
app.use('/api', apiRouter)
// there should be no ./ here
try {
client.connect();
} catch (error) {
console.error(error);
res.status(500).json({ error: "Unable to connect to database." });
};
// Port
const PORT = process.env.PORT || 3001
app.listen(PORT, () => {
console.log(`Now running on port ${PORT}`)
});
// Export
module.exports = {
client,
jwt,
bcrypt
};