我是Node.js的初学者,我无法找到我做错的事。请点击以下链接查看验证码。
Server has started...
Request for /start received.
About to route a request for /start
Request Handler 'start' was called.
_http_outgoing.js:645
throw new TypeError('First argument must be a string or Buffer');
^
TypeError: First argument must be a string or Buffer
at write_ (_http_outgoing.js:645:11)
at ServerResponse.write (_http_outgoing.js:620:10)
at Server.onRequest (H:\Docs\Codes\Web\nodejs beginner\server.js:11:14)
at emitTwo (events.js:126:13)
at Server.emit (events.js:214:7)
at parserOnIncoming (_http_server.js:602:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:117:23)
答案 0 :(得分:0)
在router.js中你有:
if(typeof handle[pathname] === 'function'){
handle[pathname]();
}
但您没有返回handle[pathname]();
它的工作原理如下:
if(typeof handle[pathname] === 'function'){
return handle[pathname]();
}
在编程时尝试使用eslint,这会警告你缺少return语句。