Skip to content

Instantly share code, notes, and snippets.

@brianyang
Created December 10, 2011 00:55
Show Gist options
  • Save brianyang/1454088 to your computer and use it in GitHub Desktop.
Save brianyang/1454088 to your computer and use it in GitHub Desktop.
node served with express on mongo in heroku
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, Mongolian = require("mongolian")
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
app.get('/save', function(req, res){
// Create a server instance with default host and port
var server = new Mongolian
// Get database
var db = server.db("test")
// Get some collections
var posts = db.collection("posts")
var comments = db.collection("comments")
// Insert some data
posts.insert({
pageId: "hallo",
title: "tester",
created: new Date,
body: "Welcome to my new blog!"
})
routes.index
});
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
$ heroku login
$ express web-app
$ vi .gitignore
node_modules
*.swp
$ cd web-app && npm install && vi Procfile
web: node app.js
$ git init && git add . && git commit -m 'init'
$ heroku create --stack cedar && git push heroku master
$ heroku ps:scale web=1
$ heroku config:add NODE_ENV=production
$ nodemon app.js
$ mongod run --config /usr/local/Cellar/mongodb/2.0.1-x86_64/mongod.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment