forked from jesumarquez/hello-mean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (34 loc) · 1.05 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
var express = require('express'),
app = express(),
mongoose = require('mongoose'),
bodyParser = require("body-parser");
//#statics
app.use('/bower_components', express.static(__dirname + '/bower_components'));
app.use('/scripts', express.static(__dirname + '/public/scripts'));
app.use(bodyParser());
//mongose
mongoose.connect('mongodb://MongoLabHigoDB:j2VCCXt1U4CLcGPECw1.fxJTp.Wr2IfdcD_l9SDsLys-@ds036698.mongolab.com:36698/MongoLabHigoDB');
//Customer Model
var Customer = mongoose.model('Customer', {
firstName : String, lastName : String
});
//routes
app.get('/', function(req, res){
res.sendFile(__dirname + '/public/index.html');
});
//api
app.post('/api/customer', function(req, res){
var customer = new Customer(req.body);
customer.save(function(err, result){
res.json(result);
});
});
app.get('/api/customer', function(req, res) {
Customer.find({}, function(err, result){
res.json(result);
})
})
//listen
app.listen(process.env.PORT, process.env.IP, null, function(){
console.log('server is running... ');
});