当我希望使用 node.js 在我的项目中部署库时,应该包含哪些文件?

发布于 2024-11-06 04:15:48 字数 168 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍白女子 2024-11-13 04:15:49

运行独立的 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.

流星番茄 2024-11-13 04:15:48

创建一个 package.json 文件,说明您的依赖项,然后使用 npm link 从该包文件进行安装。

示例包文件:

{
    "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"
    }
}

这允许您以声明方式定义依赖项,然后安装库,因为就像 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 :

{
    "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.

You can also go further and publish your own library through npm then just call npm install myLibrary on another computer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文