📜 ⬆️ ⬇️

Several NPM tools

image

NPM is a package manager for node.js , an analogue of GEM in RoR. The article provides several tips for using it.

Package installation


Everybody knows
#   express npm install express 

What other options are there?

 #   ,   package.json npm install #  express       package.json   dependencies npm install express --save #  grunt       package.json   devDependencies npm install grunt --save-dev 

Options with --save and --save-dev will only write to package.json if it already exists.
')
In order not to bother yourself, each time specifying --save, you can write:
 #  -         package.json npm config set save true 

By the way, about --save
 #  ,    ,   package.json   #    "*" -      npm update --save 

Abbreviated Command Options


To speed up the process of entering commands, it is convenient to use abbreviations. The most useful in the form of tablets:
KeyReduction
installi
uninstallr
configc
updateup
listls
--save-S
--save-dev-D

Example:
 npm install express --save #     npm i express -S 

Preparing for npm init


It is not very convenient when creating package.json using npm init to enter personal data each time. To avoid this, make the setting:
 #     " " npm set init.author.name "$NAME" npm set init.author.email "$EMAIL" npm set init.author.url "$SITE" 

Instead of environment variables $ NAME, etc. You can enter the data itself. That's it, now we are ready for npm init

And what else can you customize?


 #      npm config ls -l 

Check if the packages are out of date.


 #       update npm outdated 

Fixing package versions


 # ,     npm shrinkwrap 

Before transferring the product to commercial operation, for good, you need to fix the exact versions of the packages with which all 100% work. This team will do just that. After its execution, shrinkwrap.json will be created, in which the exact versions of your packages will be written, now npm install will install them.

NPM version upgrade


 # NPM      npm update npm -g 


PS I'm new here, if you mince karma, then at least write what's wrong

Source: https://habr.com/ru/post/206678/


All Articles