forked from naitik211/Note-MEAN.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
90 lines (83 loc) · 2.32 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
passport = require('passport'),
logger = require('mean-logger');
/**
* Main application entry file.
* Please note that the order of loading is important.
*/
// Initializing system variables
var config = require('./server/config/config');
var db = mongoose.connect(config.db);
// Bootstrap Models, Dependencies, Routes and the app as an express app
var app = require('./server/config/system/bootstrap')(passport, db);
// Start the app by listening on <port>, optional hostname
app.listen(config.port, config.hostname);
console.log('Mean app started on port ' + config.port + ' (' + process.env.NODE_ENV + ')');
// Initializing logger
logger.init(app, passport, mongoose);
var noteSchema = mongoose.Schema({
note: String
});
var note = mongoose.model('note',noteSchema);
// Expose app
//exports = module.exports = app;
//app.get('addNote')
app.post('/addNote',function(req,res){
var a = new note({name:req.body.name})
a.save(function(err){
if(err) return handleError(err);
})
var q = note.find().exec( function(err,person){
console.log(person)
});
res.json({result:'q'})
})
app.get('/note',function(req,res){
note.find().exec( function(err,notes){
res.send(notes);
});
});
app.put('/note',function(req,res){
var noteVal = req.body.newNote ;
try{
var result = eval(noteVal);
noteVal = noteVal.concat(' = ' , result);
}
catch(err){
console.log(err)
}
finally{
note.findByIdAndUpdate(req.body.id, { $set: { note: noteVal}}, function (err, tank) {
if (err) res.send({result:false});
res.send({result:true});
});
}
});
app.delete('/note',function(req,res){
note.remove({ _id: req.query.id }, function (err) {
if (err) res.send({result:false});
res.send({result:true});
});
});
app.post('/note',function(req,res){
var noteVal = req.body.note;
try{
var result = eval(noteVal);
noteVal = noteVal.concat(' = ' , result);
}
catch(err){
console.log(err)
}
finally{
var doc = new note({note:noteVal})
doc.save(function(err){
if(err)
res.json({result:false});
res.json({result:true});
});
}
});