-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (27 loc) · 1018 Bytes
/
Copy pathindex.js
File metadata and controls
41 lines (27 loc) · 1018 Bytes
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
const express = require('express');
const dotenv = require('dotenv');
const connectToMongo = require('./database ');
const { errorHandler, notFound }= require('./middleware/error.js');
const path= require('path');
var cors = require('cors');
dotenv.config();
connectToMongo();
const app = express();
app.use(cors());
app.use(express.json());// to accept json data
//Available Routes
app.use('/api/auth', require('./routes/auth'))
app.use('/api/notes', require('./routes/notes'))
// ----------------production -----------------
if (process.env.NODE_ENV === 'production')
{
//*Set static folder up in production
app.use(express.static('frontend/build'));
app.get('*', (req,res) => res.sendFile(path.resolve(__dirname, 'frontend', 'build','index.html')));
}
// ------------------production---------------
// Error Handling middlewares
app.use(notFound);
app.use(errorHandler);
const PORT = process.env.PORT || 5000;
app.listen(PORT, console.log(`Notebook backend listening on port ${PORT}`))