[英]Install NPM package if not installed using shell script
I want to write a shell script to install NPM package if not already installed. 我想编写一个Shell脚本来安装NPM软件包(如果尚未安装)。
I can use the command npm info <package-name> version
to get information about the package. 我可以使用命令npm info <package-name> version
获取有关软件包的信息。 It gives me the version if it is already there 如果已经存在,它会给我版本
2.0.0
If it is not there it gives an error. 如果不存在,则会出现错误。
npm ERR! code E404
npm ERR! 404 Not found :<package>
npm ERR! 404
npm ERR! 404 '<package>' is not in the npm registry.
How can I use this result in a conditional block to do some task depending on it? 我如何在条件块中使用此结果来根据它执行某些任务?
I think you're over-complicating things. 我认为您太过复杂了。 npm-install
already checks if the module is installed and just ignores it if it's already there, so all you need to do is call it: npm-install
已经检查模块是否已安装,如果已经安装,则将其忽略,因此您只需调用它即可:
$ npm install mymodule@2.0.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.