It results in a flat and deduplicated tree. It simplifies the overall structure by removing the duplicate packages and effectively sharing the common dependency across the multiple dependent packages. We can remove the duplicate dependencies by running npm dedupe command. Similarly, npm repo opens the GitHub repo page in the browser. If we want to check for any open issues or file any bug to npm package, we can also navigate to the website by running this command - npm bug We can quickly navigate to docs of any npm package by simply running this command - npm docs OR npm home name > package-name.txt # Let's cat package-name.txt cat package-name.txt # Output "npm-tips-and-tricks" 6. Use Pipe to pass data from one npm script to another - npm run echo-pipedata # Output > cat. npm run echo-passargument # Output > npm run echo-packagename - "hello" > echo-packagename > echo $npm_package_name "hello" npm-tips-and-tricks hello In the below example, we pass “ hello” as an argument to echo-packagename script. We can use “ - ” to pass arguments to npm script. Use npm environment variable in npm script - npm run echo-packagename # Output > echo $npm_package_name npm-tips-and-tricks - npm run echo-myvariable # Output > echo $npm_package_config_myvariable Hello World npm run echo-both-in-parallel # Output > npm run echo-hello & npm run echo-helloworld > echo-hello > echo "Hello" > echo-helloworld > echo "Helloworld" Hello Helloworld We can also run multiple scripts in parallel using “ &”. npm run echo-both # Output > npm run echo-hello & npm run echo-helloworld > echo-hello > echo "Hello" Hello > echo-helloworld > echo "Helloworld" Helloworld
#NPM CONFIG SET COMMAND SERIES#
Both the scripts run in series i.e one after the other. Run multiple scripts in a single npm script. Run a simple npm script - npm run echo-hello # Output > echo "Hello" Hello The output will be - # npm-tips-and-tricks (name of our package) Lifecycle scripts included in npm-tips-and-tricks: test echo "Error: no test specified" & exit 1 start node index.js available via `npm run-script`: echo-hello echo "Hello" echo-helloworld echo "Helloworld" echo-both npm run echo-hello & npm run echo-helloworld echo-both-in-parallel npm run echo-hello & npm run echo-helloworld echo-packagename echo $npm_package_name echo-myvariable echo $npm_package_config_myvariable echo-passargument npm run echo-packagename - "hello" echo-pipedata cat. Now, we can see all commands added above by running this command - npm run npm config set init-author-name "Ankit Jain" npm config set init-author-email " run npm init -y to automatically generate our package - , Let’s configure using npm config command. We can also set some the default init configuration like the author details etc. There is another way to automatically generate our package.json using the npm init -y command. We can run npm init command to initialize our package but it will ask information about the package, author, etc. In this article, I will be sharing NPM tips and tricks that can boost your productivity and let you use NPM in a smarter and more efficient way.
#NPM CONFIG SET COMMAND INSTALL#
Any developer who is working with Javascript has used this wonderful CLI tool to install the dependencies for their project. NPM, Node Package Manager, is the package manager for the JavaScript programming language.