Search code examples
node.jsexpressnpmnode.js-connect

express.js trouble with connect modules


I am unable to use express.js submodules and I think I'm missing something basic vis a vis npm. I'm trying to follow this tutorial to build a simple authentication system.

Path to express in app dir:

./node_modules/express/lib/express.js

My app:

var express = require('express');
var app = express.createServer();
app.use(express.bodyDecoder()); // problems happen here

and here's what happens:

meeeeee$ node app.js 

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Object #<Object> has no method 'bodyDecoder'
    at Object.<anonymous> (/Users/nflacco/Projects/santorinillc/js/auth-demo/app.js:3:17)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

Also for reference, my package.json file:

{
    "name" : "my dirty little app",
    "version" : "0.0.1",
    "dependencies" : 
    {
        "express" : "2.5.9",
        "connect" : "1.8.7",
        "optimist" : "0.3.4"
    }
}

Solution

  • The tutorial is using express 1.0.0rc4 and you're using 2.5.9. The earlier version of express has a dependency on a pre-1.x version of connect.

    bodyDecoder() was renamed to bodyParser() in connect 1.x. Change your problematic line of code to:

    app.use(express.bodyParser());

    You may also want to take a look at the 1.x to 2.x Migration Guide for express to account for any other differences between the version used in the tutorial and the one you are developing against.