2017-10-26 22:35:25 -04:00
|
|
|
.TH "NPM\-RUN\-SCRIPT" "1" "October 2017" "" ""
|
2011-11-26 09:21:03 -08:00
|
|
|
.SH "NAME"
|
2014-09-24 14:41:07 -07:00
|
|
|
\fBnpm-run-script\fR \- Run arbitrary package scripts
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.P
|
|
|
|
.RS 2
|
2014-11-04 15:08:12 -08:00
|
|
|
.nf
|
2017-07-14 10:52:48 -07:00
|
|
|
npm run\-script <command> [\-\-silent] [\-\- <args>\.\.\.]
|
2015-10-09 23:13:57 -07:00
|
|
|
|
|
|
|
alias: npm run
|
2014-11-04 15:08:12 -08:00
|
|
|
.fi
|
2014-09-24 14:41:07 -07:00
|
|
|
.RE
|
|
|
|
.SH DESCRIPTION
|
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
This runs an arbitrary command from a package's \fB"scripts"\fP object\. If no
|
|
|
|
\fB"command"\fP is provided, it will list the available scripts\. \fBrun[\-script]\fP is
|
2015-03-06 02:57:32 -06:00
|
|
|
used by the test, start, restart, and stop commands, but can be called
|
|
|
|
directly, as well\. When the scripts in the package are printed out, they're
|
|
|
|
separated into lifecycle (test, start, restart) and directly\-run scripts\.
|
2014-11-04 15:08:12 -08:00
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
As of \fBnpm@2\.0\.0\fP \fIhttp://blog\.npmjs\.org/post/98131109725/npm\-2\-0\-0\fR, you can
|
|
|
|
use custom arguments when executing scripts\. The special option \fB\-\-\fP is used by
|
2014-11-04 15:08:12 -08:00
|
|
|
getopt \fIhttp://goo\.gl/KxMmtG\fR to delimit the end of the options\. npm will pass
|
2015-07-24 15:09:52 -07:00
|
|
|
all the arguments after the \fB\-\-\fP directly to your script:
|
2014-11-04 15:08:12 -08:00
|
|
|
.P
|
|
|
|
.RS 2
|
|
|
|
.nf
|
|
|
|
npm run test \-\- \-\-grep="pattern"
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
The arguments will only be passed to the script specified after \fBnpm run\fP
|
2014-11-04 15:08:12 -08:00
|
|
|
and not to any pre or post script\.
|
2015-03-06 02:57:32 -06:00
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
The \fBenv\fP script is a special built\-in command that can be used to list
|
2015-03-06 02:57:32 -06:00
|
|
|
environment variables that will be available to the script at runtime\. If an
|
2017-10-26 22:35:25 -04:00
|
|
|
"env" command is defined in your package, it will take precedence over the
|
2015-03-06 02:57:32 -06:00
|
|
|
built\-in\.
|
2015-03-13 02:07:27 -07:00
|
|
|
.P
|
2015-07-24 15:09:52 -07:00
|
|
|
In addition to the shell's pre\-existing \fBPATH\fP, \fBnpm run\fP adds
|
|
|
|
\fBnode_modules/\.bin\fP to the \fBPATH\fP provided to scripts\. Any binaries provided by
|
|
|
|
locally\-installed dependencies can be used without the \fBnode_modules/\.bin\fP
|
|
|
|
prefix\. For example, if there is a \fBdevDependency\fP on \fBtap\fP in your package,
|
2015-07-20 20:07:07 -07:00
|
|
|
you should write:
|
|
|
|
.P
|
|
|
|
.RS 2
|
|
|
|
.nf
|
|
|
|
"scripts": {"test": "tap test/\\*\.js"}
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.P
|
2017-10-26 22:35:25 -04:00
|
|
|
instead of
|
|
|
|
.P
|
|
|
|
.RS 2
|
|
|
|
.nf
|
|
|
|
"scripts": {"test": "node_modules/\.bin/tap test/\\*\.js"}
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.P
|
|
|
|
to run your tests\.
|
|
|
|
.P
|
|
|
|
Scripts are run from the root of the module, regardless of what your current
|
|
|
|
working directory is when you call \fBnpm run\fP\|\. If you want your script to
|
|
|
|
use different behavior based on what subdirectory you're in, you can use the
|
|
|
|
\fBINIT_CWD\fP environment variable, which holds the full path you were in when
|
|
|
|
you ran \fBnpm run\fP\|\.
|
2016-01-28 18:11:35 -08:00
|
|
|
.P
|
2016-05-06 15:22:02 -07:00
|
|
|
\fBnpm run\fP sets the \fBNODE\fP environment variable to the \fBnode\fP executable with
|
2016-12-18 20:22:09 -08:00
|
|
|
which \fBnpm\fP is executed\. Also, if the \fB\-\-scripts\-prepend\-node\-path\fP is passed,
|
|
|
|
the directory within which \fBnode\fP resides is added to the
|
|
|
|
\fBPATH\fP\|\. If \fB\-\-scripts\-prepend\-node\-path=auto\fP is passed (which has been the
|
|
|
|
default in \fBnpm\fP v3), this is only performed when that \fBnode\fP executable is
|
|
|
|
not found in the \fBPATH\fP\|\.
|
2016-05-06 15:22:02 -07:00
|
|
|
.P
|
2016-01-28 18:11:35 -08:00
|
|
|
If you try to run a script without having a \fBnode_modules\fP directory and it fails,
|
|
|
|
you will be given a warning to run \fBnpm install\fP, just in case you've forgotten\.
|
2017-07-14 10:52:48 -07:00
|
|
|
.P
|
|
|
|
You can use the \fB\-\-silent\fP flag to prevent showing \fBnpm ERR!\fP output on error\.
|
2014-09-24 14:41:07 -07:00
|
|
|
.SH SEE ALSO
|
|
|
|
.RS 0
|
|
|
|
.IP \(bu 2
|
2014-09-16 15:38:50 -07:00
|
|
|
npm help 7 scripts
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2011-11-26 09:21:03 -08:00
|
|
|
npm help test
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2011-11-26 09:21:03 -08:00
|
|
|
npm help start
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2011-11-26 09:21:03 -08:00
|
|
|
npm help restart
|
2014-09-24 14:41:07 -07:00
|
|
|
.IP \(bu 2
|
2011-11-26 09:21:03 -08:00
|
|
|
npm help stop
|
2014-09-24 14:41:07 -07:00
|
|
|
|
|
|
|
.RE
|
2011-11-26 09:21:03 -08:00
|
|
|
|