0
0
Node.jsframework~20 mins

npx for running packages in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
npx Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does npx do when running a package?

Imagine you want to run a tool without installing it globally. What does npx do in this case?

AIt only runs packages already installed globally and fails otherwise.
BIt installs the package globally on your system before running it.
CIt downloads the package temporarily and runs it without installing globally.
DIt compiles the package source code before running it.
Attempts:
2 left
💡 Hint

Think about how npx helps you try tools quickly without permanent installs.

component_behavior
intermediate
2:00remaining
What happens when you run npx cowsay Hello?

Assuming cowsay is not installed globally or locally, what will npx cowsay Hello do?

AIt downloads <code>cowsay</code> temporarily, runs it to display a cow saying 'Hello', then removes the package.
BIt throws an error because <code>cowsay</code> is not installed locally or globally.
CIt installs <code>cowsay</code> globally and then runs it.
DIt runs a cached version of <code>cowsay</code> from a previous install.
Attempts:
2 left
💡 Hint

Remember how npx handles packages not installed yet.

📝 Syntax
advanced
2:00remaining
Which npx command runs a specific package version?

You want to run version 1.2.3 of the package http-server without installing it. Which command is correct?

Anpx install http-server@1.2.3
Bnpx http-server@1.2.3
Cnpx run http-server 1.2.3
Dnpx http-server --version 1.2.3
Attempts:
2 left
💡 Hint

Use the syntax to specify package version directly after the package name.

🔧 Debug
advanced
2:00remaining
Why does npx mytool fail with command not found even though mytool is installed locally?

You installed mytool locally with npm install mytool. Running npx mytool gives command not found. What is the likely cause?

AThe <code>package.json</code> file is missing a <code>bin</code> entry for <code>mytool</code>.
BYou must install <code>mytool</code> globally to run it with <code>npx</code>.
CYou need to run <code>npm link mytool</code> before using <code>npx</code>.
DThe local <code>node_modules/.bin</code> folder is missing or corrupted.
Attempts:
2 left
💡 Hint

Check how npx finds executable commands in local packages.

state_output
expert
2:00remaining
What is the output of this command sequence?

Given no global or local install of figlet, what will be the output of running these commands in order?

npx figlet Hello
npx figlet Hello
ABoth commands print 'Hello' in ASCII art, downloading the package each time.
BBoth commands fail because <code>figlet</code> is not installed globally or locally.
CThe first command runs, the second throws an error about missing package.
DThe first command downloads and runs <code>figlet</code>, the second uses a cached version to run faster.
Attempts:
2 left
💡 Hint

Think about how npx caches packages after first use.