How to Use Executables from a Package Installed Locally in node_modules?

Better Stack Team
Updated on April 4, 2024

When you install a package locally using npm or yarn, the package's executables (if any) are typically added to the node_modules/.bin directory. You can use these executables directly from the command line or from npm scripts.

Here's how you can use executables from a locally installed package:

From the Command Line

Assuming the package provides an executable named example:

# Run the locally installed executable

This directly executes the executable from the node_modules/.bin directory.

From npm Scripts

In your package.json file, you can create npm scripts that use executables from locally installed packages. For example:

  "scripts": {
    "run-example": "example"

Now, you can run this script with:

npm run run-example

This will run the locally installed example executable.

Using npx

You can also use npx to run executables from locally installed packages without referencing the ./node_modules/.bin path directly:

npx example

This command looks for executables in the node_modules/.bin directory and automatically executes them.

Choose the method that best fits your use case, and make sure to replace example with the actual name of the executable you want to run.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github