3

To install packages for package.json in current directory you need to run npm install command.

Is it possible to install packages for package.json in specific folder, without going to that folder?`

Already found solution for bower and gulp tasks:

bower install --config.cwd=<directory>
gulp build --cwd <directory>

But missing similar functionality for npm

When I run command: npm install --prefix C:\Users\ng\Projects\Lottery\src\SPA I see an error:

npm ERR! addLocal Could not install C:\Users\ng\Projects
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--prefix" "C:\\Users\\ng\\Projects\\Lottery\\src\\SPA"
npm ERR! node v6.2.1
npm ERR! npm  v3.9.3
npm ERR! code EISDIR
npm ERR! errno -4068
npm ERR! syscall read

npm ERR! eisdir EISDIR: illegal operation on a directory, read
npm ERR! eisdir This is most likely not a problem with npm itself
npm ERR! eisdir and is related to npm not being able to find a package.json in
npm ERR! eisdir a package you are trying to install.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\ng\Projects\npm-debug.log

And from documentation:

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

Uriil
  • 11,948
  • 11
  • 47
  • 68
  • 1
    Possible duplicate of [How to npm install to a specified directory?](http://stackoverflow.com/questions/14469515/how-to-npm-install-to-a-specified-directory) – Anshuman Singh Jul 07 '16 at 11:54
  • @anshumansingh modified my question to explain the problem – Uriil Jul 07 '16 at 12:36

1 Answers1

4

This should be the solution: How to npm install to a specified directory?

Basically you are using the prefix option together with the global option: npm install --prefix path/to/prefix_folder -g

You can also have a look at the documentation.

yPhil
  • 8,049
  • 4
  • 57
  • 83
c0delama
  • 663
  • 6
  • 9
  • You probably don't have write permissions. Try to use a folder e.g. on your desktop. – c0delama Jul 07 '16 at 12:39
  • did you use the -g option? – c0delama Jul 07 '16 at 12:42
  • The documentation says: "When the global flag is set, npm installs things into this prefix. When it is not set, it uses the root of the current package, or the current working directory if not in a package already." – c0delama Jul 07 '16 at 12:48
  • Why does it say addLocal in the error? Is the errorno the same or different when you use -g? – c0delama Jul 07 '16 at 12:55
  • yes, errorno stays the same, btw I am running it with admin rights – Uriil Jul 07 '16 at 12:59
  • This guy here accidently changed his cache directory to something write protected: http://stackoverflow.com/questions/32489038/npm-err-code-eisdir-errno-4068-whenever-installing-any-package Maybe thats a solution for you too? – c0delama Jul 07 '16 at 13:03
  • I can install everything globally, and i can use npm install. Just writing some custom build scripts and would like to avoid switching to different folder – Uriil Jul 07 '16 at 13:05
  • sorry, i'm afraid i can't help you then. If you find the answer i would appreciate if you post it here. – c0delama Jul 07 '16 at 13:11