Can I use npm library without npm installed?

我怕爱的太早我们不能终老 提交于 2020-05-29 07:03:08

问题


I am developing a NodeJS application. It will be deployed with Electron. This is good because all I will need to do is to package my application in an app folder inside the Electron package, then rebrand it as described on the official Electron documentation, and I will be ready to install it on any computer.

In particular, deploying with Electron means that I don't need to have NodeJS installed on my user's computer, because the Electron package is itself a NodeJS interpreter so it is going to run out of the box completely on its own.

Now, when I installed NodeJS on my system I also got npm installed along with it. Which means that whenever I need to install a package, I can just use it from command line.

Now, the program I need to deploy will keep a repository synced and updated by pulling it from github when needed. I found a wonderful NodeJS binding for Git, nodegit, that works on its own without any need of installing anything on the target computer, which is good because I am not sure my users will have git installed. Now, every time I pull my repository I will also need to do some npm install.

Which brings up my question: I know that there is a library npm that I can use to use npm programmatically from any NodeJS program. However, is that npm library a standalone thing, or it depends on the installation of npm on the system? If so, how can I work around this problem? I need to be able to do an npm install from an Electron app deployed somewhere on an user environment that I can't assume to have anything else installed, npm in particular.


回答1:


npm install --save npm

Not sure why I thought that wouldn't work, but I tested it and it seems too :)




回答2:


If you install npm locally like you would any other process you should be able to use it just the same.

var npm = require('npm');

Then from there just use git and then install your packages.



来源:https://stackoverflow.com/questions/35330345/can-i-use-npm-library-without-npm-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!