How to install npm packages programmatically? i have multiple local repos and each has its own package.json. Now i want to install packages from all those repos into a single node_modules folder which is outside of all repos. Can someone provide a sample script/guide for this?
var repos = ['repo1', 'repo2', 'repo3'];
repos.forEach(function(repoName, index) {
//todo: install packages from this repo.
// dest: '/Users/lokesh/Documents/node_modules'
});
One option is to use gradle node plugin and use config nodeModulesDir specific a global nodeModulesDir.
node {
// Version of node to use.
version = '0.11.10'
// Version of npm to use.
npmVersion = '2.1.5'
// Version of Yarn to use.
yarnVersion = '0.16.1'
// Base URL for fetching node distributions (change if you have a mirror).
distBaseUrl = 'https://nodejs.org/dist'
// If true, it will download node using above parameters.
// If false, it will try to use globally installed node.
download = true
// Set the work directory for unpacking node
workDir = file("${project.buildDir}/nodejs")
// Set the work directory for NPM
npmWorkDir = file("${project.buildDir}/npm")
// Set the work directory for Yarn
yarnWorkDir = file("${project.buildDir}/yarn")
// Set the work directory where node_modules should be located
nodeModulesDir = file("${project.projectDir}")
}
I don't know if this is helpful, if you don't want use gradle.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.