-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (27 loc) · 953 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
const express = require('express');
const app = express();
const dotenv = require('dotenv');
const notes_data = require("./data/notes_data")
const connectDB = require('./config/db');
const { notFound, errorHandler } = require('./middlewares/errorMiddleware');
const path = require('path')
dotenv.config();
connectDB();
const PORT = process.env.PORT || 5000;
app.use(express.json());
app.use('/api/users', require('./routes/userRoutes'))
app.use('/api/notes', require('./routes/noteRoutes'))
__dirname = path.resolve()
if(process.env.NODE_ENV === 'Production') {
app.use(express.static(path.join(__dirname, '/client/build')))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})
} else {
app.get('/', (req, res) => {
res.send("API is running...")
})
}
app.use(notFound)
app.use(errorHandler)
app.listen(PORT, console.log(`Server running on ${PORT}`));