DEV Community

Andreas Bergqvist
Andreas Bergqvist

Posted on

3 2

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!

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (1)

Collapse
 
max_tulian profile image
Max (he/his)

Good information :)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay