当我希望使用 node.js 在我的项目中部署库时,应该包含哪些文件?
我使用 npm 安装大部分依赖库。现在我想将这些库添加到我的工作目录中,以便另一台计算机可以直接运行它,而无需手动下载和安装这些文件。 我在github上看到很多项目都是这样做的。
这应该怎么做呢?我应该包含哪些文件?我的大部分库都在 /usr/local/lib/node/
中
I used npm to install most of my dependent libraries. Now I would like to add these libraries to my working directory so that another computer can directly run it w/o manually downloading and installing these files.
I have seen many projects on github do this.
How should this be done? And which files should I include? Most of my libraries are in /usr/local/lib/node/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行独立的 Node.js 应用程序所需的只是应用程序代码和节点二进制可执行文件(通常位于 /usr/local/bin 下),因为它已经包含所有“本机”模块。 (请参阅下面的列表。)如果您的应用程序需要除这些之外的其他库,您需要将它们作为应用程序的一部分提供。
如果您选择使用 npm 将应用程序部署到服务器,@Raynos 下面概述的方法将很好地工作。
另一方面,如果您选择通过 git 或作为存档将应用程序部署到服务器,则需要提供应用程序所需的所有库及其依赖项。
一种方法是在应用程序主目录的“node-modules”目录下安装/复制所有必需的库。
从 [email protected] 开始,本机模块包括:assert、buffer、 child_process、控制台、常量、加密、dgram、dns、事件、freelist、fs、http、https、模块、 net、os、path、querystring、readline、repl、stream、string_decoder、sys、timers、tls、tty、url、util 和 vm。
请参阅http://nodejs.org/docs/v0.4.7/api/modules。 html 了解更多信息。
All you need to run a stand-alone node.js application is your application code and the node binary executable--typically found under /usr/local/bin--as it already contains all of the "native" modules. (See below for a list.) If your application requires other libraries than these, you'd need to provide them as part of your application.
If you choose to deploy your application to a server using npm, the method outlined below by @Raynos will work nicely.
On the other hand if you choose to deploy your application to a server via git or as an archive, you'll need to provide all of the libraries required by your application as well as their dependencies.
One way to do this is to install/copy all required libraries under the 'node-modules' directory in your application's home directory.
As of [email protected], the native modules include: assert, buffer, child_process, console, constants, crypto, dgram, dns, events, freelist, fs, http, https, module, net, os, path, querystring, readline, repl, stream, string_decoder, sys, timers, tls, tty, url, util and vm.
See http://nodejs.org/docs/v0.4.7/api/modules.html for further information.
创建一个 package.json 文件,说明您的依赖项,然后使用
npm link
从该包文件进行安装。示例包文件:
这允许您以声明方式定义依赖项,然后安装库,因为就像
npm link
一样简单。您还可以进一步通过
npm
发布您自己的库,然后只需在另一台计算机上调用npm install myLibrary
即可。Create a package.json file that states what your dependencies are then use
npm link
to install from that package file.example package file :
This allows you to declaratively define your dependancies then installing your library because as simple as
npm link
.You can also go further and publish your own library through
npm
then just callnpm install myLibrary
on another computer.