简体   繁体   English

当我希望使用node.js与我的项目一起部署库时,应该包括哪些文件?

[英]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.

相关问题 使用capistrano部署Node.js项目时,如何成功通知Airbrake部署? - How do I successfully notify Airbrake of a deployment when using capistrano to deploy a Node.js project? 使用PM2,如何将node.js应用程序部署到同一服务器上的多个环境和端口? - Using PM2, how can I deploy my node.js app to multiple environments and ports on the same server? 我的 heroku 中有 node.js 应用程序部署问题 - I am having node.js app deploy problem in my heroku 我应该何时将我的程序集部署到GAC中? - When should I deploy my assemblies into the GAC? 我应该在哪个 AWS 服务中部署我的 react 应用程序 - In which AWS service should I deploy my react app 当我作为网站部署时,是否应该分发Dataset XSD文件? - Should I distribute the Dataset XSD files when I deploy as website? 如何部署全栈 node.js 项目 - How to deploy a full-stack node.js project 托管我自己的node.js Webapp或使用托管服务进行部署 - Host my own node.js webapp or deploy using a hosting service Dokku在部署时将我的Node.js应用识别为Go应用 - Dokku recognizes my Node.js app as Go app on deploy 如何部署 Node.js 代码以在不超过免费部署层的情况下按时间间隔运行 - How do I deploy Node.js code to run on an interval without exceeding free deployment tiers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM