简体   繁体   English

构建(准备)node.js应用程序以进行生产(部署)

[英]Building (preparing) node.js application for production (deploy)

I have a project that consists of several nod.js backend applications. 我有一个包含几个nod.js后端应用程序的项目。 The apps are using the same modules (which a placed outside of each ap folder in shared location). 这些应用程序使用相同的模块(位于共享位置的每个ap文件夹之外)。 The aps they are to be deployed on differnt environments (servers), some code is for test, some for debug as usual. 它们将被部署在不同的环境(服务器)上的aps,一些代码用于测试,一些用于照常调试。

If I choosed a platform (for example PaaS nodejitsu) for one of my apps, how I'm supposed to send there only production code for one of my apps? 如果我为其中一个应用程序选择了平台(例如PaaS nodejitsu),应该如何只向其中一个应用程序发送生产代码? I deployed on nodejitsu and it just sends the app folder and uses package.json to configure the app. 我部署在nodejitsu上,它只是发送应用程序文件夹,并使用package.json配置应用程序。 But there are a bunch of code that is not need (tests) for example and some code is external. 但是,例如,有一堆不需要(测试)的代码,而有些代码是外部的。 And what If I want to obstruct server code too? 如果我也要阻塞服务器代码怎么办? How this issues are supposed to be soleved? 这个问题应该如何解决?

For front-end applications has a tons of methods to be build for production. 对于前端应用,有大量的生产方法可以构建。 I understand that the requirements are different, but didn't find any infromation on best practices fo how correctly to prepare node.js back end application for deploy. 我了解需求是不同的,但是没有发现有关如何正确准备Node.js后端应用程序以进行部署的最佳实践的信息。

Read section "Keeping files out of your package" in the NPM Developer page . 阅读NPM开发人员页面中的“将文件移出包装”部分。 It states following 它指出以下

Use a .npmignorefile to keep stuff out of your package. 使用.npmignorefile将内容排除在软件包之外。 If there's no .npmignore file, but there is a .gitignore file, then npm will ignore the stuff matched by the .gitignore file. 如果没有.npmignore文件,但是有.gitignore文件,则npm将忽略与.gitignore文件匹配的内容。 If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it. 如果要包括.gitignore文件中排除的内容,则可以创建一个空的.npmignore文件以覆盖它。

Add those test files in .gitignore 将这些测试文件添加到.gitignore

or make another branch for production in git and push the production branch. 或在git另一个生产分支并推动生产分支。

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

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