Hapi js - makemehapi Issue

时间:2015-08-19 10:31:11

标签: node.js hapijs

嗨新节点,我正在练习教程“makemehapi”在第三个作业中,我收到了以下错误。任何人都可以指出我做错了什么?

此致 苏里亚

------------ Code ---------------------

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)

1 个答案:

答案 0 :(得分:0)

您需要Inert两次。删除以下行中require变量周围的Inert

server.register(require(Inert),function(err){
    if(err) throw err;
});

要:

server.register(Inert,function(err){
    if(err) throw err;
});