Loading

Quipoin Menu

Learn • Practice • Grow

node-js / Using npx
interview

Q1. What is npx?
npx is a package runner tool that comes with npm (version 5.2+). It allows you to run Node packages without installing them globally. It either uses a locally installed version, or temporarily downloads and runs the package, then discards it. This is great for one-time commands or trying new tools.

Q2. How is npx different from npm?
npm is for installing and managing packages. npx is for executing packages. With npx, you don't need to install packages globally. For example, instead of installing create-react-app globally, you can run npx create-react-app my-app. This ensures you're always using the latest version and avoids global clutter.

Q3. What are common use cases for npx?
Common uses: running project-specific commands (like npx eslint), bootstrapping projects (npx create-react-app), running one-off scripts, executing packages without installation, and testing different versions of packages. npx also runs commands from locally installed node_modules binaries without full paths.

Q4. How does npx find the package to run?
npx first looks for the package locally in node_modules. If found, it runs that version. If not, it looks in the global npm cache. If still not found, it temporarily downloads the package, runs it, and then discards it (unless you use --no-install to prevent download).

Q5. Can you use npx with specific versions?
Yes, you can specify versions: npx create-react-app@3.4.0 my-app. This runs that specific version. You can also use tags like npx create-react-app@latest. This is useful for testing compatibility with different versions without permanent installation.