Skip to content

Instantly share code, notes, and snippets.

View ovaillancourt's full-sized avatar

Olivier Vaillancourt ovaillancourt

  • Workleap
  • Montreal, QC, Can
View GitHub Profile
/Volumes/Data/kr_devtools/kr/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:134
if(err != null) return internalCallback(err, null);
^
TypeError: object is not a function
at CALL_NON_FUNCTION (native)
at [object Object].<anonymous> (/Volumes/Data/kr_devtools/kr/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:134:28)
at [object Object].g (events.js:156:14)
at [object Object].emit (events.js:70:17)
at /Volumes/Data/kr_devtools/kr/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:367:35
@ovaillancourt
ovaillancourt / init.js
Created May 29, 2012 18:02
mongoose startup
//Includes
var uriAssembler = require('./common/util/uriAssembler.js');
//Initialize configuration data
var cfg = exports.cfg = require('./common/util/configuration.js')
.ensureLoad('/common/config/');
// [...]
//Initialize mongoose
var mongoose = require('mongoose');
var connect = require('connect')
, http = require('http');
var app = connect().use(connect.static('staticRootHere'));
var server = http.createServer(app);
var io = require('socket.io').listen(server);
@ovaillancourt
ovaillancourt / index.html
Created May 29, 2012 23:15
Socket io + static file serving with connect
<!-- This should be served by your server -->
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
@ovaillancourt
ovaillancourt / afterouter.js
Created June 4, 2012 18:04
middlleware that catches stuffs the router didn't serve.
var express = require('express');
//Create the express app;
var app = express.createServer();
app.use(app.router);
//You place this middleware right after your router so paths that the
//router can't match will go through it and finally end here.
app.use(function(req, res, next){
#!/usr/bin/env node
var application_root = __dirname,
express = require("express"),
path = require("path");
var app = express.createServer();
// Config
app.use('/my/path/to/css', require('stylus').middleware({
debug: process.env.NODE_ENV !== 'production',
}));
var Evented = function(){
this._ev = $({});
}
Evented.prototype.on = function(){
this._ev.on.apply(this._ev, arguments);
return this;
}
Evented.prototype.off = function(){
var express = require('express');
var app = express.createServer();
app.use(app.router);
app.get('/:john*', function(req,res, next){
res.send('It worked \n req.param(\'john\') = ' + req.param('john'));
});
1- If a <base> tag exists, use this as the base path, or the "mount point" by default. The mount point defaults to '' if the base tag isn't there.
2- If the user calls page.base, override the mount point extracted in point 1.
3- Always prepend the mount point.