1NPM-RUN-SCRIPT(1)                                            NPM-RUN-SCRIPT(1)
2
3
4

NAME

6       npm-run-script - Run arbitrary package scripts
7
8   Synopsis
9         npm run-script <command> [--silent] [-- <args>...]
10
11         alias: npm run
12
13   Description
14       This  runs  an arbitrary command from a package's "scripts" object.  If
15       no  "command"  is  provided,  it  will  list  the  available   scripts.
16       run[-script]  is  used  by the test, start, restart, and stop commands,
17       but can be called directly, as well. When the scripts  in  the  package
18       are  printed  out,  they're  separated  into  lifecycle  (test,  start,
19       restart) and directly-run scripts.
20
21       As of npm@2.0.0 https://blog.npmjs.org/post/98131109725/npm-2-0-0,  you
22       can  use custom arguments when executing scripts. The special option --
23       is used by getopt https://goo.gl/KxMmtG to delimit the end of  the  op‐
24       tions.  npm  will  pass all the arguments after the -- directly to your
25       script:
26
27         npm run test -- --grep="pattern"
28
29       The arguments will only be passed to the script specified after npm run
30       and not to any pre or post script.
31
32       The  env  script is a special built-in command that can be used to list
33       environment variables that will be available to the script at  runtime.
34       If an "env" command is defined in your package, it will take precedence
35       over the built-in.
36
37       In addition to the shell's pre-existing PATH, npm  run  adds  node_mod‐
38       ules/.bin to the PATH provided to scripts. Any binaries provided by lo‐
39       cally-installed dependencies can be used without the  node_modules/.bin
40       prefix.  For  example, if there is a devDependency on tap in your pack‐
41       age, you should write:
42
43         "scripts": {"test": "tap test/\*.js"}
44
45       instead of
46
47         "scripts": {"test": "node_modules/.bin/tap test/\*.js"}
48
49       to run your tests.
50
51       The actual shell your script is run within is  platform  dependent.  By
52       default,  on Unix-like systems it is the /bin/sh command, on Windows it
53       is the cmd.exe.  The actual shell referred to by /bin/sh  also  depends
54       on   the   system.    As  of  npm@5.1.0  https://github.com/npm/npm/re
55       leases/tag/v5.1.0 you can customize the  shell  with  the  script-shell
56       configuration.
57
58       Scripts  are  run  from the root of the module, regardless of what your
59       current working directory is when you call npm run. If  you  want  your
60       script  to use different behavior based on what subdirectory you're in,
61       you can use the INIT_CWD environment variable,  which  holds  the  full
62       path you were in when you ran npm run.
63
64       npm  run sets the NODE environment variable to the node executable with
65       which npm is executed.  Also,  if  the  --scripts-prepend-node-path  is
66       passed,  the  directory within which node resides is added to the PATH.
67       If --scripts-prepend-node-path=auto is passed (which has been  the  de‐
68       fault  in  npm v3), this is only performed when that node executable is
69       not found in the PATH.
70
71       If you try to run a script without having a node_modules directory  and
72       it  fails, you will be given a warning to run npm install, just in case
73       you've forgotten.
74
75       You can use the --silent flag to prevent showing npm ERR! output on er‐
76       ror.
77
78       You can use the --if-present flag to avoid exiting with a non-zero exit
79       code when the script is undefined. This lets you run potentially  unde‐
80       fined scripts without breaking the execution chain.
81
82   See Also
83       • npm help scripts
84
85       • npm help test
86
87       • npm help start
88
89       • npm help restart
90
91       • npm help stop
92
93       • npm help config
94
95
96
97
98                                  April 2021                 NPM-RUN-SCRIPT(1)
Impressum