-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 850 Bytes
/
index.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
const express = require('express')
const mongoose = require('mongoose')
const app = express()
//* Client Request setup START
const cors = require('cors')
app.use(cors({
// For Development 👇
// origin: 'http://localhost:3000'
// For Production
origin: 'https://newswire-client.onrender.com'
}))
//! End
//* dotenv configuration
require('dotenv').config();
const port = process.env.PORT
const URI = process.env.URI;
// Connect to MongoDB
mongoose.connect(URI)
.then(() => {
console.log('Connected to MongoDB')
})
.catch(() => {
console.log('Connection failed')
})
// used to send data to React
app.use(express.json())
// Routes
const newsRoutes = require('./routes/news')
app.use(newsRoutes);
// Start server
app.listen(port, () => console.log(`App listening on port http://localhost:${port}`))