Skip to content

Instantly share code, notes, and snippets.

@joeyespo
Last active June 11, 2022 17:15
Show Gist options
  • Save joeyespo/a532500f5615bf3a4bacf1f410407115 to your computer and use it in GitHub Desktop.
Save joeyespo/a532500f5615bf3a4bacf1f410407115 to your computer and use it in GitHub Desktop.
Execute a node_modules/.bin script on Windows.
@ECHO OFF
SETLOCAL
REM Speed up by checking for bin directory directly
IF NOT EXIST node_modules\.bin GOTO FINDBIN
SET BIN=.\node_modules\.bin
GOTO RUN
:FINDBIN
REM Find the current bin directory from npm, storing the result in 'BIN'
FOR /f "delims=" %%i IN ('npm bin') DO SET BIN=%%i
:RUN
SET PATH=%BIN%;%PATH%
REM Run the arguments passed into this script, including the script name
%*
ENDLOCAL
@joeyespo
Copy link
Author

joeyespo commented May 11, 2016

Drop this file anywhere in your PATH and then you can run, for example:

C:\Some Node Package>npm-exec babel -h

This will run the locally installed babel. No need to globally install it. Useful when you want to run one-off commands to locally installed pacjages without adding an npm script to package.json.

Verify that you're running the right script:

C:\Some Node Package>npm-exec where babel
C:\Some Node Package\node_modules\.bin\babel.cmd

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment