29

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

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

But by doing npm install multipart it is giving error

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

XMen
  • 29,384
  • 41
  • 99
  • 151

2 Answers2

38

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

Once you do that, your require will just be:

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).

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.

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

You can also download the tar file form github. 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.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
theprogrammer
  • 2,724
  • 1
  • 18
  • 13
  • 1
    I haven't had to do this, yet, but this is how I would do it. It's a better analog to how NPM works than nEEbz's answer, which ends up treating an external dependency like it's part of your application code... – Chris Jaynes Feb 15 '12 at 14:59
  • This is a good solution although the down side of this is the tar file should always be available everywhere its needed but if you are just deploying the compiled file to production it should not be an issue at all especially if you are just using a custom package – Christopher Pelayo Jul 07 '21 at 08:06
26

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

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 >

var multipart = require("./multipart")

im_tsm
  • 1,965
  • 17
  • 29
neebz
  • 11,465
  • 7
  • 47
  • 64