简体   繁体   English

为什么我的本地主机服务器不接受此端口号?

[英]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.

相关问题 为什么Chrome删除localhost:80的端口号? - Why does Chrome remove port number for localhost:80? HTTP服务器端口号 - HTTP server port number 为什么我创建的http服务器不能与http:// myserver:port /一起使用? - Why my http server I created not working with http://myserver:port/? 服务器可以在localhost上运行,但不能在端口80上使用ip - Server works on localhost but not with ip on port 80 为什么我无法从运行在端口 3000 上的 React 应用程序访问运行在端口 3001 上的节点服务器? - Why am I unable to access my node server running on port 3001 from my React app running on port 3000? 为什么我的应用程序挂在本地主机上? - Why is my app hanging on localhost? 如何将文件夹中的页面设置为 URL localhost:端口号? - How to set a page within a folder to the URL localhost: port-number? Nodemailer 在我的本地主机上工作,但在我的远程服务器上不工作 - Nodemailer works on my localhost but not on my remote server 节点服务器在localhost上的端口4200上的Web浏览器中不可见 - Node Server not Visible in Web Browser on Port 4200 on localhost 如何从本地节点服务器http发布到另一个端口? - how to http post from localhost node server to another port?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM