Impress your colleagues with these NPM tricks

Piero Borrelli - May 13 '19 - - Dev Community

Just like anyone else, developers enjoy knowing some little tricks to show to their colleagues or friends. Today, I have decided to write about some of these keyboard magic that you can use when working with the Node Package Manager (NPM). These won’t only impress you and the people around you, but will also make your workflow definitely faster and more concise. So now that we made this little premise, let’s start to analyze these tricks! 

#1 Package initialization

Do you want to quickly initialize a new package? Are you tired of those infinite system questions that appear when doing so? Then run npm init-y or npm init-f.These commands will allow you to skip those questions and jump straight into your next amazing project!

#2 Opening a package’s homepage

Are you working with a cool npm package you just discovered? Do you want to check its homepage to read the documentation? Then run npm home“your-package”.This command will bring you directly to the page you were looking for!

#3 Opening a package’s GitHub Repository

Similarly to the command described above, running npm repo“your-package” will take you directly to a webpage. But this time, you will get automatically redirected to the package official GitHub repository. 

#4 List all the installed packages

Why should we waste our time by opening the package.json file to check what packages we have installed? Simply run npm ls - - depth 0 and you will get the informations you were looking for. 

#5 List the available scripts

New project new scripts right? but again, having to go through the package.json file can be tedious and time-consuming. Let’s get this list by running the npm run command instead!

#6 Check packages that are not declared in package.json

Another useful command, use npm prune for performing this operation. This command will run through your package.json file and compare its content with the /node_modules content. You will receive as an output a list of all those packages that are not in the package.json file. After doing this, npm prune will remove those packages together with those which you haven’t added manually to package.json or that were npm installed without the --save flag. 

#7 Bump a package version

Need to bump a package? Simply run npm together with minor/major/patch command. 

#8 Running a test

You are probably already running the npm run test command many times a day right? but why not using the shorter version npm t which is exactly the same!

Bonus commands

Still hungry for some more npm useful command shortcuts? Then check out this bonus list I have prepared for you. 

Package installation

Global package installation

Package installation + saving as a dev dependency 

Package installation + saving as a dependency

Conclusion

Being able to impress your colleagues is great, but leaving this article being aware of all the tricks you can learn when working with a technology is even better. Hope this article helped you to discover some tricks you didn’t know about before reading it and that it inspired you to go deeper when learning something new!

To be up-to-date with content like this, don't forget to stay tuned with my blog: TheCoderSwag.com

. . . . . . . .
Terabox Video Player