Last active
August 29, 2015 13:56
-
-
Save ayxos/8813186 to your computer and use it in GitHub Desktop.
GET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require( 'mongoose' ); | |
var regModel = mongoose.model( 'Model_name'); | |
exports.getAll = function (req, res){ | |
regModel.find(function (err, entries) { | |
if (!err) { | |
res.render( 'index', { | |
title : 'RestAPI System with Mongoose and Node/Express', | |
footer : '@2014 by M.A.P.S Powered by Node.js, Express, MongoDB ', | |
entries : entries | |
}); | |
} else { | |
console.log(err); | |
res.send(500,'Get error'); | |
} | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.getById = function (req, res){ | |
regModel.findById(req.params.id, function (err, entry) { | |
if (!err) { | |
res.send(entry); | |
} else { | |
console.log(err); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment