-3

What does -S stand for in an npm command? And where the added package is added in package.json? in "devDependencies" or in "dependencies" collection?

I have seen other questions like the ones below, but none of them covers the yarn equivalence for that:

What is the equivalent of "npm install <package_name> --save" in Yarn?

What does the npm -S flag mean?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Ali Safari
  • 1,535
  • 10
  • 19

1 Answers1

1

See npm install --help (or https://docs.npmjs.com/cli/v9/using-npm/config): -S means --save which has been true by default since like forever, and is documented as:

Save installed packages to a package.json file as dependencies.

Contrary to --save-dev:

Default: false

Save installed packages to a package.json file as devDependencies.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Thanks for the answer. So what is then the yarn command for the same npm command? I know that npm i is equal to yarn add, but what about npm i -S? – Ali Safari Apr 07 '23 at 09:35
  • https://stackoverflow.com/questions/40134390/what-is-the-equivalent-of-npm-install-package-name-save-in-yarn – CodeCaster Apr 07 '23 at 09:37
  • I have seen that list, but there is no entry for npm i -S, instead there is something for npm install --save-dev, which is not exactly npm i -S. – Ali Safari Apr 07 '23 at 09:41
  • As you can read in my answer, `-S` means `--save`, which is true by default, so omitting it achieves exactly the same as specifying it. – CodeCaster Apr 07 '23 at 09:44
  • So you mean the command 'yarn add' is the same as 'npm i -S' or 'npm i', right? – Ali Safari Apr 07 '23 at 09:48
  • I conclude your answer plus the discussion under it as the answer to my question: "npm i -S pkgname" === "yarn add pkgname", and the added package is added to the dependencies in package.json file. – Ali Safari Apr 07 '23 at 10:00