如何手动安装 node.js 模块?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5778474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:05:39  来源:igfitidea点击:

How to manually install a node.js module?

file-uploadnode.jsmultipart

提问by XMen

I want to upload a file to s3 so I want to run the upload program from this article: http://www.componentix.com/blog/9

我想上传一个文件到s3,所以我想运行这篇文章中的上传程序:http: //www.componentix.com/blog/9

For this I need to install the multipart module. https://github.com/isaacs/multipart-js

为此,我需要安装 multipart 模块。 https://github.com/isaacs/multipart-js

But by doing npm install multipart it is giving error

但是通过执行 npm install multipart 它给出了错误

How should I install this multipart module so that I can get this program running?

我应该如何安装这个多部分模块,以便我可以运行这个程序?

采纳答案by neebz

Download lib folder from the https://github.com/isaacs/multipart-js(including all the files inside it).

https://github.com/isaacs/multipart-js下载 lib 文件夹(包括其中的所有文件)。

Put all those files next to your node application in the same folder.

将所有这些文件放在节点应用程序旁边的同一文件夹中。

On the top of your application file where you have included other modules like HTTP etc. ..append this >

在你的应用程序文件的顶部,你已经包含了其他模块,比如 HTTP 等。..append this >

var multipart = require("./multipart")

var multipart = require("./multipart")

回答by theprogrammer

You can download the full repo (not just the lib folder) into your application under a folder with the name node_modules.

您可以将完整的 repo(不仅仅是 lib 文件夹)下载到名为node_modules.

Once you do that, your requirewill just be:

一旦你这样做了,你require就会:

var multipart = require('multipart');

This is due to the way node resolves module dependencies. It will always look for a node_modulesdirectory at the root of your app (and a few other places as well).

这是由于节点解决模块依赖关系的方式。它将始终node_modules在您的应用程序的根目录(以及其他一些地方)寻找一个目录。

It's important you download the full repo and not just the lib folder if you plan to use it this way since the package.jsonfile is used to find the main entry point.

如果您打算以这种方式使用它,那么下载完整的 repo 而不仅仅是 lib 文件夹很重要,因为该package.json文件用于查找主入口点。

 { "name" : "multipart"
, "version" : "0.0.0"
, "description" : "A JavaScript library for parsing and writing multipart messages"
, "contributors" :
  [ "Isaac Z. Schlueter <[email protected]>"
  , "John Wright <[email protected]>"
  ]
, "repository" :
  { "type" : "git"
  , "url" : "http://github.com/isaacs/multipart-js.git"
  }
, "main" : "lib/multipart"
}

The advantage of this is compatibility with using npm install locally in your dev machine.

这样做的好处是与在您的开发机器中本地使用 npm install 兼容。

You can also download the tar file form github. Hit the Downloadbutton and deploy that with your app. Once that is done in your server you can run

您也可以从 github 下载 tar 文件。点击下载按钮并将其部署到您的应用程序中。一旦在您的服务器中完成,您就可以运行

npm install <path-to-the-tar-file>

That will install multiparton the machine for you.

这将为您安装multipart在机器上。