-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
57 lines (52 loc) · 1.53 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
const express = require('express')
const app = express()
// var loginController = require('./controller/loginController');
app.set('view-engine','ejs')
app.use(express.static('./public'));
app.get('/',(req,res)=>{
res.render('index1.ejs')
})
app.get('/login',(req,res)=>{
res.render('login.ejs')
})
app.get('/insight',(req,res)=>{
res.render('insight.ejs')
})
app.get('/map',(req,res)=>{
res.render('map.ejs')
})
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost:27017/mydb");
var nameSchema = new mongoose.Schema({
uname: String,
email: String,
upass: String,
messagea: String,
messageb: String
},{collection: 'Employee'});
var User = mongoose.model("User", nameSchema);
//--------------------------------------------------------------------
app.get('/insight', function(req, res){
user.find({}, function(err, docs){
if(err) res.json(err);
else res.render('insight', {users: 'ramo'});
});
});
//--------------------------------------------------------------------------------
app.post("/addname", (req, res) => {
var myData = new User(req.body);
myData.save()
.then(item => {
res.render('insight.ejs');
})
.catch(err => {
res.status(400).send("Unable to save to database");
});
});
// loginController(app);
app.listen(3000)
app.use(express.static('views'));