[英]Which files should I include when I wish to deploy a library with my project using node.js?
I used npm to install most of my dependent libraries. 我使用npm安装了大多数依赖库。 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.
我已经在github上看到许多项目都可以做到这一点。
How should this be done? 应该怎么做? And which files should I include?
我应该包括哪些文件? Most of my libraries are in
/usr/local/lib/node/
我的大多数库都在
/usr/local/lib/node/
Create a package.json file that states what your dependencies are then use npm link
to install from that package file. 创建一个package.json文件,声明您的依赖项,然后使用
npm link
从该程序包文件进行安装。
example package file : 示例包文件:
{
"name": "Inventory-System",
"description": "Manage Inventory web app",
"version": "0.0.1",
"author": "Raynos",
"dependencies": {
"now": "0.5.3",
"backbone": "0.3.2",
"cradle": "0.5.5",
"supervisor": "0.1.2",
"less": "1.0.41",
"ejs": "0.4.1"
}
}
This allows you to declaratively define your dependancies then installing your library because as simple as npm link
. 这使您可以声明性地定义依赖关系,然后安装库,因为它就像
npm link
一样简单。
You can also go further and publish your own library through npm
then just call npm install myLibrary
on another computer. 您还可以进一步通过
npm
发布自己的库,然后只需在另一台计算机上调用npm install myLibrary
。
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. 运行独立的node.js应用程序所需要的就是应用程序代码和节点二进制可执行文件(通常在/ usr / local / bin下),因为它已经包含所有“本机”模块。 (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. 如果您选择使用npm将应用程序部署到服务器,则@Raynos下面概述的方法将很好地工作。
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. 另一方面,如果您选择通过git或作为归档将应用程序部署到服务器,则需要提供应用程序所需的所有库及其依赖项。
One way to do this is to install/copy all required libraries under the 'node-modules' directory in your application's home directory. 一种方法是在应用程序主目录的“ node-modules”目录下安装/复制所有必需的库。
As of Node@0.4.7, 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. 从Node@0.4.7开始,本机模块包括:断言,缓冲区,child_process,控制台,常量,crypto,dgram,dns,事件,freelist,fs,http,https,模块,net,os,路径,querystring,readline ,repl,stream,string_decoder,sys,timers,tls,tty,url,util和vm。
See http://nodejs.org/docs/v0.4.7/api/modules.html for further information. 有关更多信息,请参见http://nodejs.org/docs/v0.4.7/api/modules.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.