Things I want to do
This is a brief explanation of npm, which often comes up when researching Node.js or JavaScript/TypeScript.
This section summarizes the basics of package management.
What is NPM?
NPM is a package management system used with Node.js.
(In reality, it has various functions in addition to package management, such as package execution.)
Official page

install
Package installation using NPM is performed using the following command.
npm install packageNameThe command `install` can also be replaced with any of the following: `add`, `i`, `in`, `ins`, `inst`, `insta`, `instal`, `isnt`, `isnta`, `isntal`, or `isntall`.
I think the actual commands you’ll see are ‘install’ or ‘i’.
Options regarding the installation location
Local installation
If you don’t specify an installation location, or if you set –save-prod and -P, it will be installed in the node_modules folder within the project.
Installation information is stored in the ‘dependencies’ section of package.json.
example:
npm install appLocal installation (dev)
Setting –save-dev and -D will install it into the node_modules folder within your project.
Installation information is stored in ‘devDependencies’ within package.json.
example:
npm install app -DGlobal installation
Setting –global and -G will install the software outside of the project.
The path is automatically configured, allowing you to run installed packages from anywhere.
example:
npm install app -GThe difference between –save-prod (no options) and –save-dev
If you install using –save-prod (without any options), the installed packages will be included in the final output, but if you install using –save-dev, they will not be included.
In short, libraries referenced from HTML and JS (such as jQuery and threejs) should be installed with –save-prod (no options), while packages for the environment and build process (such as Electron and TypeScript) should be installed with –save-dev.
install without arguments
When you run `install` without any arguments, as shown below, it will automatically read the necessary packages from `Package.json`, etc. This is useful when you’ve cloned a template from Git, etc., and need to retrieve the necessary packages.
npm installList of installed packages
The following command can be used to list packages using NPM.
npm ls`install` can be replaced with any of the `list` commands.
Options regarding the installation location
Similar to installation, if no arguments are specified, a list of locally installed packages will be displayed. (However, there is no distinction between Dependencies and devDependencies.)
example:
npm lsUse the -g option to list globally installed packages.
example:
npm ls -gUninstall
Package installation using NPM is performed using the following command.
npm uninstall packageNameUninstall can be replaced with any of the following: unlink, remove, rm, r, or un.
You can check the installed packages using `npm ls`, as explained in ‘List of installed packages’. (The version name will also be displayed, but you don’t need the version name.)
Packages installed with –save-dev (-D) or –global (-G) must also be uninstalled using –save-dev (-D) or –global (-G).


コメント