英文:
Port Number In Node.js
问题
我正在学习如何使用http
模块在Node.js中创建服务器。尽管我正在努力理解如何确定需要使用哪个端口号。我应该如何找到我的端口号,还是可以随便选择一个数字?它在所有设备上都不同吗?有没有可以选择的列表?
我对这个话题非常困惑,有人可以解释一下吗?
英文:
I am learning how to create servers in Node.js using the http
module. Although I am struggling to understand how to figure out what port number I need to use. How am I supposed to find my port number or can I just use any number? Is it different across all devices? Is there a list I can choose from?
I am very confused about this topic can someone please explain?
答案1
得分: 1
你可以基本上选择监听任何你想要的端口,只要满足以下条件:
- 没有其他进程已经在监听它
- 端口0-1023是“受限制的端口”。在基于Unix的操作系统上,你需要超级用户权限来绑定它们,而在其他操作系统上,这被认为是一种不好的做法。
Node.js应用程序通常会监听端口3000或4000,但这只是约定,你不必遵循它们。
英文:
You can essentially pick to listen on whatever port you wish, provided that:
- No other process is already listening on it
- Ports 0-1023 are "restricted ports". On a unix-based operating system you'll need superuser privileges to bind them, on other operating systems it's just considered a bad practice.
Node.js applications often listen on port 3000 or 4000, but those are just conventions, and you don't have to follow them.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论