Skip to content

Instantly share code, notes, and snippets.

@iamtrk

iamtrk/app.js

Last active Dec 20, 2015
Embed
What would you like to do?
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