reggi/overrides
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: npm-set-script |
| 3 | section: 1 |
| 4 | description: Set tasks in the scripts section of package.json |
| 5 | github_repo: npm/cli |
| 6 | github_branch: release/v8 |
| 7 | github_path: docs/lib/content/commands/npm-set-script.md |
| 8 | redirect_from: |
| 9 | - /cli-documentation/v8/cli-commands/npm-set-script |
| 10 | - /cli-documentation/v8/cli-commands/set-script |
| 11 | - /cli-documentation/v8/commands/npm-set-script |
| 12 | - /cli-documentation/v8/commands/set-script |
| 13 | - /cli-documentation/v8/npm-set-script |
| 14 | - /cli-documentation/v8/set-script |
| 15 | - /cli/v8/cli-commands/npm-set-script |
| 16 | - /cli/v8/cli-commands/set-script |
| 17 | - /cli/v8/commands/set-script |
| 18 | - /cli/v8/npm-set-script |
| 19 | - /cli/v8/set-script |
| 20 | --- |
| 21 | |
| 22 | ### Synopsis |
| 23 | |
| 24 | An npm command that lets you create a task in the `scripts` section of the `package.json`. |
| 25 | |
| 26 | Deprecated. |
| 27 | |
| 28 | ```bash |
| 29 | npm set-script [<script>] [<command>] |
| 30 | ``` |
| 31 | |
| 32 | **Example:** |
| 33 | |
| 34 | - `npm set-script start "http-server ."` |
| 35 | |
| 36 | ```json |
| 37 | { |
| 38 | "name": "my-project", |
| 39 | "scripts": { |
| 40 | "start": "http-server .", |
| 41 | "test": "some existing value" |
| 42 | } |
| 43 | } |
| 44 | ``` |
| 45 | |
| 46 | ### Configuration |
| 47 | |
| 48 | #### `workspace` |
| 49 | |
| 50 | - Default: |
| 51 | - Type: String (can be set multiple times) |
| 52 | |
| 53 | Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option. |
| 54 | |
| 55 | Valid values for the `workspace` config are either: |
| 56 | |
| 57 | - Workspace names |
| 58 | - Path to a workspace directory |
| 59 | - Path to a parent workspace directory (will result in selecting all workspaces within that folder) |
| 60 | |
| 61 | When set for the `npm init` command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project. |
| 62 | |
| 63 | This value is not exported to the environment for child processes. |
| 64 | |
| 65 | #### `workspaces` |
| 66 | |
| 67 | - Default: null |
| 68 | - Type: null or Boolean |
| 69 | |
| 70 | Set to true to run the command in the context of **all** configured workspaces. |
| 71 | |
| 72 | Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly: |
| 73 | |
| 74 | - Commands that operate on the `node_modules` tree (install, update, etc.) will link workspaces into the `node_modules` folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, _unless_ one or more workspaces are specified in the `workspace` config. |
| 75 | |
| 76 | This value is not exported to the environment for child processes. |
| 77 | |
| 78 | #### `include-workspace-root` |
| 79 | |
| 80 | - Default: false |
| 81 | - Type: Boolean |
| 82 | |
| 83 | Include the workspace root when workspaces are enabled for a command. |
| 84 | |
| 85 | When false, specifying individual workspaces via the `workspace` config, or all workspaces via the `workspaces` flag, will cause npm to operate only on the specified workspaces, and not on the root project. |
| 86 | |
| 87 | This value is not exported to the environment for child processes. |
| 88 | |
| 89 | ### See Also |
| 90 | |
| 91 | - [npm run-script](/cli/v8/commands/npm-run-script) |
| 92 | - [npm install](/cli/v8/commands/npm-install) |
| 93 | - [npm test](/cli/v8/commands/npm-test) |
| 94 | - [npm start](/cli/v8/commands/npm-start) |