[英]Why this port number is not acceptable for my localhost server?
I have a hapi.js code as below: ` 'use strict'; 我有一个hapi.js代码,如下所示:`'use strict';
const hapi = require("hapi");
const server = new hapi.Server();
server.connection({
host: 'localhost',
port: 2922,
});
server.route({
method: 'GET',
path: '/hello',
handler: function (req, res) {
res('Hello world from hapi.js');
}
});
server.start((err) => {
});
` The problem is that when I run this server with port number 22291 it executes and exit immediately without any error, What is the reason for? `问题是,当我使用端口号22291运行此服务器时,它立即执行并退出,没有任何错误,这是什么原因? I am using linux centos 7 我正在使用linux centos 7
You need to check for the error in the start callback: 您需要在启动回调中检查错误:
server.start((err) => {
if (err) throw err;
});
That will give you the details you need to debug. 这将为您提供调试所需的详细信息。 Always make sure to check for errors in callbacks or you'll repeatedly run into this problem in Node. 始终确保检查回调中的错误,否则您将在Node中反复遇到此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.