简体   繁体   English

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

[英]How to manually install a node.js module?

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. 为此,我需要安装multipart模块。 https://github.com/isaacs/multipart-js 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? 我应该如何安装这个多部分模块,以便我可以运行这个程序?

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 require will just be: 一旦你这样做,你的require将是:

var multipart = require('multipart');

This is due to the way node resolves module dependencies. 这是由于节点解析模块依赖关系的方式。 It will always look for a node_modules directory 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.json file 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 <i@izs.me>"
  , "John Wright <mrjjwright@gmail.com>"
  ]
, "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. 您也可以从github下载tar文件。 Hit the Download button and deploy that with your app. 点击“ 下载”按钮,然后使用您的应用进行部署。 Once that is done in your server you can run 一旦在您的服务器中完成,您就可以运行

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

That will install multipart on the machine for you. 这将在机器上为您安装multipart

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等..支持此>

var multipart = require("./multipart")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM