
It’s important to understand what’s happening under the hood when installing packages in order to solve issues and to make the dependency tree and the final bundle size as small as possible.įirst of all, we need a good overview of the dependency tree and which package versions have actually been installed. No more installing and maintaining tools as global packages. The latest version of create-react-app will be downloaded and executed immediately. Here, the binary NPX comes to the rescue and saves a lot of work for us! For example, to start a new react-project you can simply write: Also, most of the tools you will only use once or twice.
#Npm config set version install
This was time-consuming, not only to install but to maintain all your tools for multiple projects. Grunt, gulp, react-create-app, react-native-cli and mocha are just a few.īefore NPM 5.x you had to install these tools either as global packages or as devDependencies. There are many scripting tools on NPM out there that you probably will use but will not be a part of your runtime bundle. Nice! Now, go to the folder myproject and writeĭone! Take a closer look at the folder structureĪs you can see, myproject/node_modules/mypackage is now a symlink to the folder mypackage! Now you can continue to develop mypackage and all changes you make will be instantly available in myproject. Go to the folder mypackage and write npm link We want mypackage to be a dependency of myproject. Let’s say we have a project called myproject and a package called mypackage. The easiest way to understand package linking is to try it out! In this way, you can edit packages locally and the changes will be instantly available in the project using it. Package linking works by creating a symlink in your node_modules folder that points to the local repository of your package. Committing and pushing your package to a remote repository for every change you want to try out is tiresome! ? Instead, you can use a feature called package linking.

Sometimes you want to work on a project and develop its packages at the same time. ? Bonus shortcut! Are you not using GitHub? No worries, there are shortcuts for BitBucket and GitLab as well: npm i bitbucket:username/myrepositorynpm i gitlab:username/myrepository 4. Just add # together with the branch name at the end. There’s more! You can also install a package from a specific branch. (Change username to your username on GitHub.) npm iĮven better, if you’re using a GitHub repository, you can use this shortcut: For example, if you have your own fork of Redux, you can install your package directly from your fork. When making your own packages or pull-requests for existing packages, this feature is powerful. Install packages from different sourcesīy default, when running npm-install, NPM will install the latest version from the npm-registry ( )īut there’s more! NPM can install packages from other sources as well, like an URL or a tarball file. If you’re unsure about the names just install them one by one. Why write multiple lines when you can write one? If you know your packages by heart, the fastest option is to install them all in a one-liner, but be careful! One misspelled package and the whole command will fail. ? Bonus shortcut! Wanna impress your colleagues? Here it comes… You’ll save time you can spend on something meaningful, like drinking an extra cup of coffee ☕️ ?

A shortcut for a command might seem like a trivial thing, but the truth is that you will write 30–60% less code. This is one of the most useful but not so well-documented features. Today I want to share my top 10 tricks with you. Let’s call them tricks, things that drastically improved my way of working with NPM.

After using NPM for almost 8 years, I’ve learned things along the way that I wish I knew when I started.
