-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·29 lines (24 loc) · 943 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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
const injuries = require('./routes/api/injuries');
const upload = require('./routes/api/upload');
//Bodyparser middleware
app.use(bodyParser.json());
//CORS Headers
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
//Connection MongoDB
mongoose.connect('mongodb://nagesh:[email protected]:43317/talem', { useNewUrlParser: true })
.then(()=> console.log('mongoDB connected'))
.catch(err=> console.log(err));
//Declaring Route
app.use('/api/injuries', injuries);
app.use('/api/upload', upload);
//configuring server on port 5000
const port = process.env.port || 5000
app.listen(5000, () => console.log(`server started on port ${port}`));