-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (37 loc) · 1.24 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express');
const path = require('path');
const cors = require('cors');
const bodyParser = require('body-parser');
//import router
const userRoute = require("./route/user.route");
const teacherRoute = require('./route/teacher.route');
const studentRoute = require('./route/student.route');
const adminRoute = require('./route/admin.route');
const app = express();
const server = require('http').Server(app);
const port = 5000;
//connet database
const mongoose = require('mongoose');
// mongoose.connect('mongodb://127.0.0.1:27017/class-survey-database');
mongoose.connect('mongodb://admin:[email protected]:45507/class-survey-database');
// Cross Origin Error
app.get('/', (req, res) => {
res.json("HI ban");
})
app.use(cors({ credentials: true, origin: true }));
app.use(bodyParser.json());
//user route
app.use('/users', userRoute);
//teacher route
app.use('/teachers', teacherRoute);
//student route
app.use('/students', studentRoute);
//admid route
app.use('/admins', adminRoute);
// server.listen(5000, () => {
// console.log('Listening on port ' + 3000);
// });
server.listen(process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || port, () => {
console.log('Listening on port ' + port);
});
module.exports = app;