G
G
gomerIT2020-11-11 18:47:03
Node.js
gomerIT, 2020-11-11 18:47:03

How to install dependencies from a past project into a new package.json?

I read that it's enough just to transfer the package.json to a new project and run the command

npm i

But I would like to understand this. To install dependencies from the previous project to the new one, in the previous project they had to be installed using
--save
or
--save-dev
or it does not play a role in any way and you can install packages simply
npm i name
?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2020-11-11
@Aetae

There is no command, but --savethere is --save-prod(which is not needed, because by default).
--save-dev- obviously installs devDependencies.
Development dependencies go to devDependencies, dependencies for the application itself go to dependencies (by default). For local development, there is no difference (except for the organization) - they all fly in a bunch to node_modules, however, if you make your own ready-made module for npm, then when you install such a module, only the usual dependencies will be installed.

D
Dmitry Belyaev, 2020-11-11
@bingo347

npm ithis is a short version npm install
Without parameters, it installs dependencies from package.json and if there is a package-lock.json file, it normalizes the node_modules folder according to it.
npm i namewill install the package name version tagged with latest (the default tag) will
npm i [email protected]install the package name version tagged with tag will
npm i [email protected]install the package name version 5.xx where xx is the last of 5 will
npm i [email protected]install the package name version 5.3.x where x is the last of 5.3 will
npm i [email protected]install the package name version 5.3 The .1
parameter --saveor its short version -Swill store the dependency in package.json in the dependencies section, this has been the default behavior for some time now when package.json is present
the parameter --save-devor its short version -Dwill save the dependency in package.json in the devDependencies section.
And only you can decide how to install in your particular case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question