View on GitHub

Tech, Games and Whisky

The Sebr's Blog

npx

|

For Stingray Tools developement, we have started to use npm more and more. We use it to install typescript, ts-lint and a few other tools.

This article explains what npx is about. This is kind of next level npm has it helps you make better use of npm. The whole article covers a lot of interesting topics but one was more relevant for our use of npm.

npx to run locally-installed tools

Lots of npm users will install commonly used tools like typescript globally.

npm install typescript -g

This type of global installation even ensure that you can invoke the tools from the command line in a convenient way:

> tsc --project . --watch

But if you want to run multiple versions of the same tools, things become a little bit more complicated. We have used typescript in Stingray for the past few months. During which the versions of Stingray have gone from 2.3 to 2.4.1 (with multiple dot releases in between). This means we install typescript locally instead of globally. And this means starting the typescript compiler needs more typing:

> node_modules/typescript/bin/tsc -p . -w 

Granted this is not the end of the world but this is still more typing! Enter npx which allows you to run tools from your local installation:

> npx  tsc --project . --watch

npx goes really beyond this cool little feature. Give it a try.