1

Let's assume that I have a directory in my intranet, which contains a node_modules folder, which contains all the dependencies, which I need for my web-project to work. As far as I know, I can type something like (in the terminal from my project's root folder):

npm i "\\RepoComp\Repo\node_modules\bootstrap"

So, it will install bootstrap package into my project. It's quite good, but I wouldn't like to install all of the packages, listed in my package.json manually, I'd like to type just:

npm i <path-to-intranet-repo>

And I expect npm to gather all of the dependencies from this intranet location. How can I achieve this?

PS: Actually, what I try to achieve - is placing all dependencies to remote folder in intranet location, so all the developers in my team can access needed packages from there, without internet connection. Is it possible? However, as I found from npm-debug.log, it attempts to connect to registry.npmjs.org, while trying to install packages through npm --prefix "\\RepoComp\Repo\node_modules\" install command.

klutch1991
  • 229
  • 2
  • 16
  • What you're looking for is a *private* NPM repository. Please see e.g. http://stackoverflow.com/q/7575627/272735 that addresses your root problem. – user272735 May 02 '17 at 09:44
  • 1
    Possible duplicate of [can you host a private repository for your organization to use with npm?](http://stackoverflow.com/questions/7575627/can-you-host-a-private-repository-for-your-organization-to-use-with-npm) – user272735 May 02 '17 at 09:44
  • @user272735, doesn't seem to work for me – klutch1991 May 02 '17 at 09:56

3 Answers3

1

You can use the npm install <folder> variant with the --prefix option.

npm --prefix ./path-to-intranet install

References:

You could also try:

(cd intranet-location && npm install)

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
  • `npm --prefix "\\RepoComp\Repo\node_modules\" install` causes "error parsing json" during "angular" dependency installation – klutch1991 May 02 '17 at 08:11
  • it also says: `npm ERR! failed to fetch from registry: https://registry.npmjs.org/@angular%2fanimations` – klutch1991 May 02 '17 at 08:13
  • Did it install other modules? – Suhail Gupta May 02 '17 at 08:14
  • No, "node_modules" folder doesn't even appear in projects root folder. – klutch1991 May 02 '17 at 08:15
  • Why did you do `npm --prefix "\\RepoComp\Repo\node_modules\`? You need to give the path till `Repo` – Suhail Gupta May 02 '17 at 08:15
  • What do you mean as "path till"? `"\\RepoComp\Repo\node_modules"` is actual path to my repo. Am I wrong? – klutch1991 May 02 '17 at 08:16
  • Doesn't the project's `package.json` reside inside `Repo`? We need to send `npm --prefix "\\RepoComp\Repo\" install` as the command – Suhail Gupta May 02 '17 at 08:18
  • Doesn't seem to work even after placing package.json to remote folder. Actually, what I try to achieve - is placing all dependencies to remote folder in intranet location, so all the developers in my team can access needed packages from there, without internet connection. Is it possible? However, as I found from `npm-debug.log`, it attempts to connect to registry.npmjs.org, while trying to install packages. – klutch1991 May 02 '17 at 08:21
  • You also said to try `(cd intranet-location && npm install)` but it seems to install packages into remote folder, doesn't it? – klutch1991 May 02 '17 at 08:27
1

switch from npm to yarn and use it's offline-mirror feature. see Running Yarn offline

lecstor
  • 5,619
  • 21
  • 27
0

I am not sure in which platform you are working in.

But assuming you are working in some LINUX virtual machine (like putty or something). I think you just need to export the path of the correct npm path which is using this node_modules.

$bash
$export PATH=/path/to/the/dir:$PATH

For other cases around, use the 'prefix' config defaults to the location where node is installed. On most systems, this is /usr/local. On windows, this is the exact location of the node.exe binary.

For more guidance: refer to this doc

Bidisha Pyne
  • 543
  • 2
  • 13