0
我使用nodejs連接模塊代碼作爲示例。 app.js遵循此:node.js連接模塊錯誤信息
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);
節點app.js EXCUTE它,打印錯誤消息在這個控制檯:
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)
操作系統:Mac OS X Lion的10.7.3
節點: 0.6.11
connent:2.1.3
Thx,這是連接版本的情況。同一個問題的鏈接:http://stackoverflow.com/questions/9571239/mac-os-x-nodejs-has-no-method-router-error – mackjoner 2012-04-22 13:21:04