【发布时间】:2015-05-16 12:56:24
【问题描述】:
我在 GitHub twit NPM 中找到并使用代码创建应用程序:
-> express twitter
-> in the app.js:
var T = new Twit({
consumer_key: 'AAA',
consumer_secret: 'BBB',
access_token: 'CCC',
access_token_secret: 'DDD'
})
T.post('/update', { status: 'hello world!' }, function(err, data, response) {
console.log(data)
})
// I write it in the end of whole code that generated by express. But when I start
it with the comand node app.js it prints "undefined" and 404 Not Found when
I run it from browser.
谁知道,我该如何解决这个问题?我也有路线文件夹。但是除了快速生成的代码之外我没有其他任何东西。
【问题讨论】:
-
app.js 的第 30 行是什么?
-
app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); });这个错误是当我去localhost:3000/update@Ryan -
删除或评论该行并重试。 app.use() 将在我认为你不想要的每个请求上运行该函数。
-
除非您知道有问题,否则您不想调用 next(err)。如果没有问题,您的中间件应该调用 next();
-
@Ryan 现在打印
Cannot GET /update
标签: node.js