This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
62 lines (54 loc) · 1.54 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var User = require('./userSchema.js');
//Creating Server using express()
var app = express();
//use method for static files
app.use(express.static(__dirname));
//Connecting to mongodb loaclhost database
mongoose.connect(process.env.MONGODB_URI||"mongodb://localhost:27017/nimbus" ,{ useNewUrlParser: true });
//Using Body parser for middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({strict:false}));
app.get('/register',function (req,res){
console.log("okay");
res.sendFile(__dirname+"/register.html");
});
app.get('/events',function (req,res){
console.log("okay");
res.sendFile(__dirname+"/events.html");
});
app.get('/',function (req,res){
console.log("okay");
res.sendFile(__dirname+"/main.html");
});
app.get('/team',function (req,res){
console.log("okay");
res.sendFile(__dirname+"/team.html");
});
app.get('/sponsors',function (req,res){
console.log("okay");
res.sendFile(__dirname+"/sponsers.html");
});
//Post Method
app.post('/adduser',function(req, res){
var data = req.body;
console.log(req.body.team);
var user=new User(data);
console.log(user);
user.save(function(err,user,numAffected){
if(err){
console.log(err);
res.send('500');
}
else{
console.log("added",user);
res.send(user);
}
});
});
// Listening to port-number
app.listen(3000,function(){
console.log("localhost at 3000");
});