Created
October 18, 2012 01:46
-
-
Save jwulf/3909415 to your computer and use it in GitHub Desktop.
just some mongoose node code asking for help
This file contains 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 express = require('express') | |
, restaurant = require('./routes/restaurant') | |
, http = require('http') | |
, config = require('./config') | |
, stylus = require('stylus'); | |
var app = express(); | |
require('./db'); | |
app.configure(function(){ | |
app.set('port', process.env.PORT || 3000); | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'jade'); | |
app.use(stylus.middleware({ | |
src: "" + __dirname + "/views", | |
dest: "" + __dirname + "/public", | |
compress: true | |
})); | |
app.use(express.favicon()); | |
app.use(express.logger('dev')); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(express.cookieParser('my super sekret hash')); | |
app.use(express.session({ | |
secret: 'my super sekret hash' | |
})); | |
app.use(app.router); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
}); | |
app.configure('development', function(){ | |
app.use(express.errorHandler()); | |
}); | |
var routes = require('./routes'); | |
app.get('/', routes.index); | |
app.get('/users', user.list); | |
app.get('/restaurants', restaurant.list); | |
http.createServer(app).listen(app.get('port'), function(){ | |
console.log("Express server listening on port " + app.get('port')); | |
}); |
This file contains 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'), | |
Schema = mongoose.Schema; | |
var restaurantSchema = new Schema({ | |
Name: String, | |
Address: String | |
}); | |
mongoose.connect(process.env.MONGOHQ_URL); | |
exports.Restaurant = mongoose.model('Restaurant', restaurantSchema, 'Restaurant'); |
This file contains 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 db = require('mongoose'), | |
Restaurant = require('./db').Restaurant; | |
exports.list = function(req, res){ | |
Restaurant.find({}, function(err, restaurants){ | |
if(err){ | |
console.log(err); | |
} | |
var title = 'Sweet'; | |
console.log(restaurants); | |
res.render('restaurant', { title: title, restaurants: restaurants }); | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment