I need to add a dependency in my package.json and load module, by taking user input in command prompt while running npm install.
Is it possible to do so.
I need to add a dependency in my package.json and load module, by taking user input in command prompt while running npm install.
Is it possible to do so.
As you haven't provided much information about what exactly you try to accomplish, it's difficult to advise you or give a concrete example. Anyhow, in package.json
, you can override the default behavior of npm scripts with the scripts
field:
"scripts": {
"install": "./scripts/install.sh",
}
As someone else has noted before, you cannot call npm install
in your custom script, though, as this would lead to infinite recursion. Thus, rather provide a preinstall
script, which npm
runs before install
.
For use cases other than adding dependencies based on user input, I recommend to check how to set the environment variables and configurations, which the user then could override with npm config set project-name:config-name config-value
.