npx alternative for yarn

1 min read  •  25 Mar 2023
Views:

npx is a cli tool used to execute npm package binaries without installing them globally on your machine. Similarly we can also use yarn to run npm package binaries in a temporary environment without installing them globally. We can use the yarn dlx command which comes with Yarn v2 to do it.


Upgrading yarn

yarn set version berry
yarn-upgrade

Example

For example, suppose we have to uglify a javascript file using a npm package such as uglify-js without installing it globally on our machine, we can do it as follows-

yarn dlx uglify-js test.js -o test.min.js
yarn-dlx-example