Do you need to pass command line arguments dynamically to a package.json script? This is how to do it.
Static command line arguments can be set with the scripts.
"cli": "node ./src/build-helper-cli.js -V"
The script can be called as follows.
$ npm run cli
Now lets pass it a command line argument dynamically.
$ npm run cli -- add-eslint-disable --dest build
The trick are the two dashes (–) which tell npm what follows are command line arguments for the script being executed. That is it. Easy right?
Today I wanted to add a file from a package that I had installed globally with NPM to Webstorm. Where does NPM install the global packages on Windows? How to find the location?
As always, once you know how it is simple. Just execute the following command from cmd.
npm config ls -l | grep prefix
That will show you the location. Which is probably something like
I recently needed to add internationalization (i18n) functionality to an existing GitHub repository. I made the changes and put in a pull request. That pull request has not been processed yet. In the mean time I wanted to use my updated version. After some googling around I found out it is possible to manage modules directly from GitHub (git) with npm.
Such a cool feature. It means I can use my updated version until the main repository is updated. It is really easy, just change the line in the
package.json file if you already have the module imported.
And then run
npm install command. The module will be replaced with the git version.
If you have not installed the module yet just execute the following command.
npm install --save <module name> <git repo>
npm install --save vue2-flip-countdown https://github.com/nidkil/vue2-flip-countdown
Is this cool or what?
I needed to install pm2 globally and run it as non root. This meant installing it with npm without using the sudo command. However, when you do this npm will throw an error.
“Error: EACCES: permission denied”
The npm documentation does provide a solution that works, which has a caveat.
- Make a directory for global installations:
- Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
- Open or create a ~/.profile file and add this line:
- Back on the command line, update your system variables:
As a side note, an easier way to execute step 3 is:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile
When I initially executed these steps it worked. However, after logging out and in again the
pm2 command was no longer available. It turns out that on login the
.bash_profile file is loaded instead of the
.profile. Actually bash will try loading ~/.bash_profile, ~/.bash_login and ~/.profile, in that order. Once it finds one of them it will not try and load any of the others. After adding the statement to
.bash_profile it worked like a dream.
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bash_profile
Hope this helps someone.