简体   繁体   English

如何在实时服务器上上传Node.js项目或安装Node.js和NPM模块

[英]How to upload nodejs project or install nodejs and npm modules on live server

I've made a real time chat application with node and socket io and it is running well in my local machine. 我已经用node和socket io制作了一个实时聊天应用程序,它在我的本地计算机上运行良好。 But its time to run it on my live windows server. 但是是时候在我的实时Windows服务器上运行它了。 I can't understand to how set it up there. 我不明白该如何设置。 Do I need to upload the files to the server or I've to install node js and npm modules in the server and then upload the files. 我是否需要将文件上传到服务器,还是必须在服务器中安装node js和npm模块,然后上传文件。 And how I can do these? 我该怎么做? How I'll run the command prompt as we do in local machine like node chat.js ? 我将如何像在节点chat.js这样的本地计算机中那样运行命令提示符? Any help is appreciated. 任何帮助表示赞赏。 Thanks in advance. 提前致谢。

You can use a deployment client like Capistrano or you can just upload your source files then run npm install (assuming your have node installed) followed by your commands to bring up the server. 您可以使用Capistrano之类的部署客户端,也可以仅上传源文件,然后运行npm install(假设已安装节点),然后运行命令来启动服务器。 I'd suggest using a framework like meteor or sails to make deployment easier. 我建议使用流星或帆这样的框架来简化部署。 Or using a cloud solution like heroku . 或者使用诸如heroku之类的云解决方案。

You can use Jenkins for deploying your app to server. 您可以使用Jenkins将应用程序部署到服务器。 Running bash commands and setting builds are much more easier. 运行bash命令和设置构建要容易得多。

Keep it simple: 把事情简单化:

  1. Download and install NodeJS, NPM ( here ) 下载并安装NodeJS,NPM( 在此处
  2. You need to establish a simple way to move your files to the remote server. 您需要建立一种简单的方法将文件移动到远程服务器。 Since you can run your code and do the development at your local machine, I recommend you to use github for this purpose. 由于您可以运行代码并在本地计算机上进行开发,因此我建议您为此使用github。 Set up a repository and clone it at your remote server. 设置存储库并将其克隆到远程服务器上。 Then, you can always push and pull your changes using git. 然后,您始终可以使用git推送和拉出更改。
  3. You need to establish a simple way to run your code at the remote server. 您需要建立一种简单的方法来在远程服务器上运行代码。 Since you use Windows, I recommend you to create a .bat file that does all the preparations and runs your code. 由于使用Windows,因此建议您创建一个.bat文件,该文件将进行所有准备工作并运行您的代码。 In the simplest case, it would contain node path\\to\\project\\chat.js . 在最简单的情况下,它将包含node path\\to\\project\\chat.js Then, run this file using a console. 然后,使用控制台运行此文件。 If you're going to use github, you probably should include this .bat file to your repository. 如果要使用github,则可能应将此.bat文件包括在存储库中。

Good luck! 祝好运!

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

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