-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 904 Bytes
/
index.js
File metadata and controls
36 lines (28 loc) · 904 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
var express = require("express");
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var path = require('path');
var app = express();
var collegeRouter = require('./routes/collegeRouter');
var studentRouter = require('./routes/studentRouter');
app.get('/', function(req,res){
res.sendFile(path.join(__dirname+'/public/index.html'));
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use('/api/colleges', collegeRouter);
app.use('/api/students', studentRouter);
app.use(express.static(path.join(__dirname,'public')));
mongoose.connect("mongodb://localhost/mydb",{
useNewUrlParser: true
})
.then(function(){
console.log("database connected");
})
.catch(function(err){
console.log("could not connect to database")
});
const PORT = 3000;
app.listen(PORT, function() {
console.log("Server running on port : " + PORT);
});