简体   繁体   English

如何将Node.js REST API部署到生产模式

[英]How to deploy Node.js REST API to production mode

I've created a REST API using Node.js and Express, so now I need to share it and publish it on a server in order to connect from Front-end. 我已经使用Node.js和Express创建了REST API,所以现在我需要共享它并将其发布在服务器上,以便从前端进行连接。 Can you tell me a proper way to do it? 你能告诉我合适的方法吗?

The question you are asking is very broad. 您要问的问题很广泛。 It can be done in a lot of ways. 它可以通过很多方式来完成。 For me this 2 part tutorial was very helpful: https://hackernoon.com/tutorial-creating-and-managing-a-node-js-server-on-aws-part-1-d67367ac5171 . 对我来说,这个分​​为2部分的教程非常有帮助: https : //hackernoon.com/tutorial-creating-and-managing-a-node-js-server-on-aws-part-1-d67367ac5171 However, this only covers the installation on AWS EC2. 但是,这仅涵盖在AWS EC2上的安装。 This doesn't differ much from deploying it to Google Cloud, Azure or something local. 这与将其部署到Google Cloud,Azure或本地应用程序没有太大区别。

In general you need to fix the following steps: 通常,您需要修复以下步骤:

1) Create a server somewhere (local or in the cloud) 1)在某处(本地或云中)创建服务器

2) Install all the stuff to run your app. 2)安装所有东西以运行您的应用程序。 In your case Node.js at least 至少在您的情况下,Node.js

3) Put a copy of your app on the server 3)将您的应用程序副本放在服务器上

4) Run it with node 4)用节点运行

5) Go to the ip of the server 5)转到服务器的IP

The tutorial gives more details. 本教程提供了更多详细信息。 DISCLAIMER: If you actually want to use this in production there is way more to consider. 免责声明:如果您确实想在生产中使用此功能,则有更多方法可以考虑。 For example, security policies, setting up proxies, installing certificates etc. Please read up on that properly before you start running production apps. 例如,安全策略,设置代理,安装证书等。在开始运行生产应用之前,请仔细阅读该内容。

You can install node on the the production server and then where the project is situated just . 您可以将节点安装在生产服务器上,然后在项目所在的位置进行安装。

copy that path 复制该路径

Open the Cmd >> 打开Cmd >>

Enter "cd copied path .>>enter 输入“ cd复制路径。>>输入

you npm will be install & REST Api will Work. 您将安装npm并使用REST Api。

You could use Heroku for deployment, this way you can know how your app will fare. 您可以使用Heroku进行部署,这样您就可以知道应用程序的运行情况。 It's free moreover. 而且是免费的。
If you're satisfied with it then you can go ahead and buy a dyno or use other platforms like Azure or AWS. 如果对此感到满意,则可以继续购买dyno或使用Azure或AWS等其他平台。

To learn more on how to deploy your existing app to Heroku, visit this page . 要了解有关如何将现有应用程序部署到Heroku的更多信息,请访问此页面

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

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