javascript - Programmatic calls to npm from node.js script -
i writing custom command line interface (cli) manage other packages installed or uninstalled npm
. better call npm via spawn('npm')
or require('npm')
?
require('child_process').spawn; var _npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'; var npm = spawn(_npm, ['install', source]);
or:
require('npm').commands.install(source, function (err, data) { ... });
i have spawn
approach in place, ran 1 issue spawn
on windows. wondering if using require('npm')
mitigate other unforeseen issues?
are there major disadvantages switching `require('npm'), other lack of documentation?
require('npm') mitigate other unforeseen issues?
generally yes, if library provides direct javascript api, going preferred option integrating own javascript program.
the docs here. agree bit slim, if understand command line interface, api going make lot of sense. plus it's open source don't afraid read source.
Comments
Post a Comment