如何打包 &部署 Node.js + Express Web 应用程序? [英] How to package & deploy Node.js + express web application?

查看:72
本文介绍了如何打包 &部署 Node.js + Express Web 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Node.js 编程的新手,最近我使用(express、backbone 和其他免费视图技术,使用 mongoDB)创建了一个示例工作 Web 应用程序.现在我想在临时环境中部署相同的应用程序,但我不确定如何打包和分发该应用程序.[我可以照顾mongoDb并单独设置]

I am new to Node.js programming and I have recently created a sample working web application using (express, backbone & other complimentary view technologies, with mongoDB). Now i am at a point where I want to deploy the same on a staging environment and I am not sure how to package this application and distribute the same. [I can take care of mongoDb and setting it up seperately]

我来自 Java 世界,在那里我们为部署在 servlet 容器中的 Web 应用程序创建可重用库和 war/ear 包的 jar.现在在这种情况下,由于 node.js 本身也充当 Web 容器,我该如何打包我的 Web 应用程序?

I am from Java world and in there we create jars for reusable libs and war/ear packages for web applications which is deployed in a servlet container. Now in this case since node.js itself acts as a web container as well, how do i package my webapp?

  1. 是否有使用 express 构建的打包节点 web 应用程序的任何标准格式/指南?(节点应用程序是否有类似的 jar/war 打包系统?)
  2. 打包后如何部署?它会成为一个exe,因为它也是它自己的容器吗?

PS:到目前为止,我只想手动将所有需要的源文件复制到暂存环境中,然后运行 ​​npm 命令来下载该机器上的所有依赖项,然后使用永远"或其他一些机制来运行我的服务器.js.(另外,添加某种监控,以防应用程序崩溃并永远失败)我不确定这是否正确?我相信一定有一些标准化的方法来解决这个问题.

PS: As of now I am thinking of just manually copying all the required source files into the staging environment and run npm commands to download all dependencies on that machine and then use 'forever' or some other mechanism to run my server.js. (Also, add some sort of monitoring, just in case app crashes and forever fails) I am not sure if that is the right way? I am sure there must be some standardized way of addressing this problem.

推荐答案

没有标准化的方法,但您走在正确的轨道上.如果您的 package.json 是最新的并且保存完好,您只需将您的应用目录复制/压缩/克隆到生产系统,不包括 node_modules.

There is no standardized way, but you're on the right track. If your package.json is up to date and well kept, you can just copy/zip/clone your app directory to the production system, excluding the node_modules.

在您的生产系统上,运行npm install 安装你的依赖项,npm test 如果你有测试,最后 NODE_ENV=production node server.js

On your production system, run npm install to install your dependencies, npm test if you have tests and finally NODE_ENV=production node server.js

我认为最近的一些幻灯片非常有用,其中还包括诸如永远这样的包装器主题,可以在 找到这里.

Some recent slides I considered to be quite helpful that also include the topic of wrappers like forever, can be found here.

这篇关于如何打包 &部署 Node.js + Express Web 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆