简体   繁体   English

如何获取在本地主机上运行的node.js应用程序?

[英]How to get node.js app that runs on localhost online?

I made a node.js chat app using express and socket.io. 我使用express和socket.io制作了一个node.js聊天应用程序。 It runs on localhost and other computers can connect to it on the same network. 它在localhost上运行,其他计算机可以在同一网络上连接到它。 How could I get it online so people on different networks could still use it? 我如何才能在线获取它,以便其他网络上的人们仍然可以使用它?

Here's my package.json just in case it helps: 这是我的package.json,以防万一:

{
  "name": "Node Chat",
  "version": "1.0.1",
  "description": "Simple chat server",
  "dependencies": {
    "express": "4.10.2",
    "socket.io": "1.2.0"
  }
}

You have to put your app on a computer that can be contacted from the open internet with a public IP address. 您必须将您的应用程序放在可以通过开放式互联网使用公共IP地址与之联系的计算机上。 If you want to be able to contact it with an URL such as http://www.example.com , then that entails the following steps: 如果您希望能够使用诸如http://www.example.com之类的URL与之联系,则需要执行以下步骤:

  1. Finding a server that has a publicly accessible IP address that you can run your app on. 查找具有可公开访问的IP地址的服务器,您可以在该服务器上运行您的应用程序。 Usually, this would be a server at a hosting company that supports node.js apps. 通常,这将是托管公司中支持node.js应用程序的服务器。

  2. Setting up a DNS entry to make your domain and the www prefix point to the proper IP address that contains your sever process. 设置DNS条目以使您的域和www前缀指向包含您的服务器进程的正确IP地址。

  3. Running your server process in a way that it responds to port 80 requests. 以响应端口80请求的方式运行服务器进程。 At a hosting company, there may be specific rules to follow in order to make port 80 at your domain work the way you want. 在托管公司,可能需要遵循一些特定规则,以使您域中的端口80能够按您希望的方式工作。

You could achieve these steps from a server on your own local network, but that would typically involve a bunch of network configuration to "punch" a hole your local firewall and to route port 80 requests to a specific server on your network (usually using port forwarding) and to allow external requests to reach a given server on your private network and it would involve some DNS configuration to allow a domain name request to match up with the public IP of your private network. 您可以从您自己的本地网络上的服务器上实现这些步骤,但这通常会涉及大量网络配置,以“打孔”本地防火墙,并将端口80请求路由到网络上的特定服务器(通常使用端口转发)并允许外部请求到达您的专用网络上的给定服务器,这将涉及一些DNS配置,以允许域名请求与您的专用网络的公共IP匹配。 For a variety of reasons, this configuration is usually not recommended if this is a home network. 由于各种原因,如果这是家庭网络,通常不建议使用此配置。

Since you are working with node.js I expect you to have at least some experience with websites in general and that you know that they need to be hosted on a server. 由于您正在使用node.js,因此我希望您至少对网站有一定的了解,并且知道它们需要托管在服务器上。 You could do this yourself, but since you are asking this question I assume you are not having the equipment to do this. 您可以自己执行此操作,但是由于您是在问这个问题,所以我认为您没有设备来执行此操作。 But like mentioned in the comments of your post there are several providers for hosting node apps. 但是,就像您的帖子评论中提到的那样,有多个提供商可以托管节点应用程序。 Most of them offer limited free services, which will totally do it if you make this app for you and some friends. 他们中的大多数人提供有限的免费服务,如果您为自己和一些朋友制作这个应用程序,这将完全做到这一点。 Here is a short list: 以下是简短列表:

You can find an extended list here . 您可以在此处找到扩展列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM