Expressjs POST错误:TypeError:无法读取未定义的属性“标题”

我想了很多,为什么这会引发这个错误:

Configuring Listening on 2000 TypeError: Cannot read property 'title' of undefined at /home/abdulsattar/learning/node/express/index.js:9:20 

index.js:

 var express = require("express"), app = express.createServer(); app.get("/", function(req, res) { res.send('<form action="/new" method="post"><input type="text" name="title" /><input type="submit" /></form>'); }); app.post("/new", function(req, res) { res.send(req.body.title); }); app.configure(function() { console.log("Configuring"); app.use(express.bodyParser()); }); var port = process.env.PORT || 2000; app.listen(port, function() { console.log("Listening on " + port); }); 

我读过快递需要bodyParser() 。 我use上面的d,但总是失败。 我在版本2.5.82.5.8上尝试过(认为可能是问题),但两个版本都失败了。 有什么我失踪?

我的直觉,尝试移动你的app.get和app.post之前的app.configure语句。 bodyParser中间件没有被调用。 另外,为了安全,将enctype添加到表单中,不应该是必需的,但不pipe: application/x-www-form-urlencoded

让我知道…