Skip to content

Instantly share code, notes, and snippets.

@iamtrk
Last active December 20, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamtrk/6055731 to your computer and use it in GitHub Desktop.
Save iamtrk/6055731 to your computer and use it in GitHub Desktop.
Simple wiring of mongoose, Node.js and express
var express = require('express')
, http = require('http')
, foodlist = require('./foodlist');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.use(express.bodyParser());
});
app.get('/mnf/:manufacturer',function(req,res){
console.log(req.params.manufacturer)
foodlist.fudlist(req.params.manufacturer, function(err,teams){
console.log(teams.length+"This stuff is kool"+err);
res.send(teams[1].get("nutrients"));
});
});
http.createServer(app).listen(app.get('port'),function(){
console.log("Server has started and is listening on "+app.get('port'));
});
var mongoose = require('mongoose');
var db = mongoose.connection;
var messageSchema = mongoose.Schema({
manufacturer:String
});
exports.fudlist = function(manufacture, callback){
mongoose.connect('mongodb://localhost/enron');
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
var essage = mongoose.model('foods',messageSchema);
essage.find({'manufacturer':manufacture}, function (err, teams) {
if(err){
onErr(err,callback);
}else{
mongoose.connection.close();
console.log(teams.length);
callback("",teams)
}
})
}); };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment