嗨,New Node,我正在练习教程“ makemehapi”。在第三份作业中,我收到以下错误。有人可以指出我做错了什么吗?
问候,
苏里亚
------------代码---------------------
var Path = require('path');
var Hapi = require('hapi');
var Inert = require('inert');
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: Number(process.argv[2]|| 8080)
});
server.register(require(Inert),function(err){
if(err) throw err;
} )
server.route({
method:'GET',
path:"/index.html",
handler: {
file: "index.html"
}
})
server.start(function () {
console.log('Server running at:', server.info.uri);
});
----------------------错误--------------------------
assert.js:86
throw new assert.AssertionError({
^
AssertionError: path must be a string
at Module.require (module.js:364:3)
at require (module.js:384:17)`enter code here`
at Object.<anonymous> (/home/surya/Desktop/nodeschool/Hapi Practice/test/Lesson3.js:13:17)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
✗ Error connecting to http://localhost:18384: ECONNREFUSED
events.js:85
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
最佳答案
您需要两次输入Inert
。在以下行中删除require
变量周围的Inert
:
server.register(require(Inert),function(err){
if(err) throw err;
});
至:
server.register(Inert,function(err){
if(err) throw err;
});