简体   繁体   English

启动Node js应用

[英]Starting Node js app

So I created a node app that uploads pictures and the app works locally, I can upload stuff from all of my home devices and they end up in my designated upload folder. 因此,我创建了一个节点应用程序,该节点应用程序可以上传图片,并且该应用程序可以在本地运行,我可以从所有家庭设备中上传内容,它们最终位于我指定的上传文件夹中。 Next thing is to go global, so I moved the app to an FTP server and... I don't know how to start it. 下一步是全球化,因此我将应用程序移至FTP服务器,并且...我不知道如何启动它。 I can't go 我不能去

node server.js

like I do on my PC in cmd, can I? 就像我在cmd中的PC上一样,可以吗? I open my index page but when I upload something I get: Server responded with 0 code. 我打开索引页面,但是当我上传内容时,我得到:服务器响应0。 Just like when I open my index.html without starting the node app trough cmd on my PC. 就像我打开index.html而不在PC上启动cmd上的节点应用程序时一样。 I'm a front-end guy and I don't know almost anything about servers and I've searched quite a bit around the internet, but to little avail. 我是前端人员,对服务器几乎一无所知,我在互联网上进行了大量搜索,但收效甚微。

Before a node app can run on a server you need to make sure that: 在节点应用程序可以在服务器上运行之前,您需要确保:

  1. Node is installed 节点已安装
  2. npm install has successfully run / or all dependencies must be transferred to the app directory in the right place npm install已成功运行/或所有依赖项必须转移到正确位置的应用程序目录中
  3. The port of the node server should be reachable, so the routing must be set up correctly. 节点服务器的端口应可访问,因此必须正确设置路由。

Also, you can't start a program from an ftp prompt usually. 另外, 通常无法从ftp提示符下启动程序

One fairly quick way to get this set up would be to sign up for a virtual server on Amazon using their EC2 server instances. 进行此设置的一种相当快捷的方法是使用其EC2服务器实例在Amazon上注册虚拟服务器。 Just choose the basic instance (whichever one is free for the first year) and then install Node and run npm install on your root directory once you have uploaded the files. 只需选择基本实例(第一年免费),然后安装Node并在上传文件后在根目录上运行npm install。 Also if you are going to want this site accessible with your own domain you will have to set up an elastic IP address also available via Amazon (AWS). 同样,如果您希望该站点可以通过您自己的域访问,则必须设置一个弹性IP地址,该地址也可以通过Amazon(AWS)获得。 Furthermore if you want to have your url accessable via the standard port 80 (meanning that you don't have to type your url:[port number]/path then you might want to look into setting up a reverse proxy using something like nginx. 此外,如果您希望通过标准端口80访问url(这意味着您不必键入url:[端口号] / path,那么您可能希望考虑使用诸如nginx之类的设置反向代理。

I know this sounds like a lot and i won't lie to you this is kind of complicated but there is a lot more to getting a node application up an running that you might expect. 我知道这听起来很像,但我不会对您说谎,这有点复杂,但是要使节点应用程序正常运行还需要您做很多事情。

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

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