node.js - 如何在特定目录中安装 npm 包

标签 node.js npm

要在当前目录中安装 package.json 的软件包,您需要运行 npm install 命令。

是否可以在特定文件夹中安装 package.json 的软件包,而无需转到该文件夹​​?`

已经找到了 Bower 和 gulp 任务的解决方案:

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

但缺少 npm 的类似功能

当我运行命令时:npm install --prefix C:\Users\ng\Projects\Lottery\src\SPA 我看到一个错误:

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

来自 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

最佳答案

这应该是解决方案:How to npm install to a specified directory?

基本上,您将前缀选项与全局选项一起使用:npm install --prefix <path/to/prefix_folder> -g

您还可以查看 documentation .

关于node.js - 如何在特定目录中安装 npm 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38244461/

相关文章:

gruntjs - 如何卸载npm包?

node.js - 是否可以从 package.json 目录外部运行 package.json 中定义的脚本?

angular - 如何编写 Angular2 npm 模块 - Angular2 RC 6

javascript - Socket.IO 向特定数量的客户端广播

javascript - Electron 登录/注册等

Node.js 命名空间

node.js - 错误 TS1259 : Module '"./node_modules/@types/express/index "' can only be default-imported using the ' esModuleInterop' 标志

node.js - NPM 和 jsdom 错误加载

MySQL - 获取没有时区偏移的日期

javascript - 错误: Unable to find module 'opennebula' (Meteor.JS)