【问题标题】:How to correctly install Node modules to subfolder?如何正确将 Node 模块安装到子文件夹?
【发布时间】:2014-12-03 15:04:11
【问题描述】:
官方方法是什么让node_modules文件夹创建在子文件夹中?我将 Bower 用于客户端文件,并愉快地将它们安装在“客户端”文件夹下。将 NPM 用于服务器端依赖项并遵循相同的模式会很棒。例如:
MyApplication
client
bower_modules
server
node_modules
.bowerrc
package.json
server.js
根据 NPM 文档,可以将节点模块安装到默认位置以外的文件夹中。不幸的是,使用 --prefix 选项会阻止 package.json 的依赖项部分被填充......这让我相信这不是正确的做法。
【问题讨论】:
标签:
node.js
npm
mean-stack
【解决方案1】:
我会这样做:
git mv package.json server # (or just mv if you aren't using git)
cd server
npm install
【解决方案2】:
node_modules 和 package.json 相互跟随,因此您必须移动 package.json 或将 node_modules 移动到项目的根目录。
您仍然可以拥有客户端和服务器文件夹,这是个好主意!
MyApplication
node_modules
express
socket.io
client
bower_components/jquery/jquery.js
client.js
server
server.js
.bowerrc
package.json
server.js