简体   繁体   English

在 NodeJS 中安装 NPM 包

[英]Installing NPM packages in NodeJS

I've tried using ChildProcess to achieve this, here's the code for that:我已经尝试使用 ChildProcess 来实现这一点,这是代码:

cp.exec("npm i <package>", {cwd: process.cwd()});

Which returns no errors, and doesn't actually install the package它没有返回错误,并且实际上并没有安装 package

I'm wondering what I'm doing wrong or if there are any other ways to achieve this.我想知道我做错了什么,或者是否有任何其他方法可以实现这一目标。

There are many packages that allow you to install packages, I personally tried using "npm-programmatic" and "npm".有很多包可以让你安装包,我个人尝试使用“npm-programmatic”和“npm”。 The code I showed was valid, but when I was executing it, it was installing the modules to my main project.我显示的代码是有效的,但是当我执行它时,它正在将模块安装到我的主项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM