DEV Community

Andreas Bergqvist
Andreas Bergqvist

Posted on

npx, at you command

Since version 5.2 of npm (released almost 2 years ago) you also received the command npx.

With npx you can run the binaries for your project dependencies (like npx webpack or npx jest).

But you can also run any command from any package available on npm!
Here are some of my favorites!

npx http-server

Starts a webserver in the current folder. Great if you want to test something really quick.

npx create-react-app my-app

Use create-react-app without the need to first install it globally. Just run npx.

npx shx touch file # Create a file
npx shx mkdir folder # Create a folder

The shx command lets you run shell commands, cross-platform! Great if you want to share command snippets that both Mac and Windows users might use.

npx sort-package-json

Sorts the keys in your package.json (if there is a package.json in the current directory).

npx speed-test

Test your internet connection

npx typescript index.ts --out index.js

If you want to check the result when TypeScript transforms a .ts file to a .js.
Notice, this is probably for more simple files and mostly if you want to investigate how it works, since you don't use an config file.

npx terser index.js > index.min.js

Minify a Javascript file.

npx ntl

Gives you an interactive list of available NPM scripts (if you are in a folder with an package.json).

npx puppeteer-cli print https://itiden.se page.pdf
npx puppeteer-cli screenshot https://itiden.se page.png

Create an PDF or screenshot from an URL. Notice that Chromium is downloaded when this command i run which makes it quite slow. But might come in handy if you quickly want an PDF or screenshot of an webpage!

And, if you'd like, you can set up your own "card" to display in the terminal. See:
https://dev.to/wuz/setting-up-a-npx-username-card-1pip

So...

npx andreasbergqvist

Feel free to comment on more commands that might come in handy!

Top comments (1)

Collapse
 
max_tulian profile image
Max (he/his)

Good information :)