-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (37 loc) · 1.17 KB
/
app.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 app = express();
const bodyParser = require('body-parser')
const cors = require('cors')
const morgan = require('morgan')
const dotenv = require("dotenv")
app.use(morgan('dev'))
app.use(bodyParser.json())
app.use(cors());
dotenv.config()
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log('connected to the mongoDB !!!')
}).catch((e) => {
console.log('Error connecting to mongoDB !!!', e)
})
const Auth = require('./routes/auth/auth')
const News = require('./routes/parser/news')
const Xenon = require('./routes/xenon/xenon')
const Weather = require('./routes/weather')
const UserMiddleware = require('./middlewares/userMiddleware')
app.use('/news', UserMiddleware, News)
app.use('/auth', Auth)
app.use('/xenon', Xenon)
app.use('/weather', Weather)
app.get('/', (req, res) => {
res.send("WELCOME TO THE NEWS APP API\n")
});
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that out!")
})
app.listen(process.env.PORT || 4000, (req, res) => {
console.log('app listening on port 4000!')
})