I use the nodejs connent modul code for sample. app.js follow this:
var connect = require("connect");
connect(
connect.static(__dirname + "/public"),
// create a router to handle application paths
connect.router(function(app) {
app.get("/sayHello/:firstName/:lastName", function(req, res) {
var userName = req.params.firstName + " " + req.params.lastName,
html = "<!doctype html>" + "<html><head><title>Hello " + userName + "</title></head>" + "<body><h1>Hello, " + userName + "!</h1></body></html>";
res.end(html);
});
})
).listen(8000);
node app.js excute its, print error message on console of this:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object function createServer() {
function app(req, res){ app.handle(req, res); }
utils.merge(app, proto);
utils.merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [].slice.apply(arguments);
return app;
} has no method 'router'
at Object.<anonymous> (/Users/yangzhaojie/tech/nodejs/devsample/app4.js:6:10)
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)
os: Mac OS X Lion 10.7.3
node: 0.6.11
connent: 2.1.3
You must be using an old tutorial or something. The router middleware was removed from Connect some time ago: https://github.com/senchalabs/connect/issues/262
You can either use another module like this one (connect-router) or switch to Express.