-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
42 lines (35 loc) · 1.06 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
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const taskRoutes = require('./routes/taskRoutes');
const userRoutes = require('./routes/userRoutes');
require('colors');
require('dotenv').config();
// express app
const app = express();
// CORS
app.use(cors({
origin: ['http://localhost:3000', 'https://ticker.kevinpaul.xyz']
}));
// middleware
app.use(express.json())
app.use((req, res, next) => {
console.log(`Route: ${req.path} | Request: ${req.method}`.bold.cyan);
next();
})
// routes
app.use("/api/tasks", taskRoutes);
app.use("/api/users", userRoutes);
// connect to mongoDB
mongoose.connect(process.env.MONGO_URI)
.then(() => {
console.log(`MongoDB: Connected to Database.`.bold.underline.green);
// listener
const PORT = process.env.PORT;
app.listen(5000, () => {
console.log(`Server running on PORT ${PORT} in ${process.env.NODE_ENV} mode`.bold.underline.white)
})
})
.catch((error) => {
console.log(`${error}`.bold.red)
})