Using npx instead of global packages

Published in December 3, 2019
2 minutes reading

I recently discovered the existence of npx, a npm package runner that comes installed since the version 5.2.0. The great benefit of npx is to make it easier to use CLI tools (command-line interface).

One thing that always bothered me was the need to install global package, and would use them a few times. Installing global packages always come with some problems, such as incompatible versions of the same package between different projects.

To exemplify how the npx works, I will create a React application. For this we execute the npx create-react-app hello-world command (Note that we haven't installed the create-react-app globally to create the application).

React application creation with npx
React application creation with npx (Source: the author)

According to the npx docs, it will check if the given command exists in the $PATH or in the project binaries (node_modules/.bin). If found, it will be executed, otherwise the package will be installed temporarily before execution.

The features of npx go far beyond that demonstrated and can be checked in the docs. There is also a introductory post very interesting about the npx which further describes the other features.

References

Comments

Douglas Fuelber

Developed by Douglas Fuelber | 2022