package.json
file records all the installed packagepackge.json
$ npm init
package name : The name of package; name
property of package.json
version : npm version is strictly managed (we will go through deeply later)
entry point : entry point for JavaScript executable file. Often the last module.exports
file
git repository : repository
property of package.json
keywords : enable user to find the package easily in npm official site (https://npmjs.com) keywords
property of package.json
scripts
in package.jsonscript
property specifies npm
command line i.e., npm run [SCRIPT COMMAND]
in consolenode [FILE NAME]
under start
command and execute npm start
like React.js, Vue.js##. 5 — save
option
--save
option for npm install
command is often used for tutorials--save
option adds package name to dependencies
but it’s default from npm@5
; Therefore, no need to specify --save
option for npm install
command— save-dev
option--save-dev
option for packages only for development i.e., nodemon
provides hot loading whenever the source code is changed and it’s often used only for development--save-dev
can be abbreviated to -D
// console
npm install --save-dev nodemand
// package.json
{
...
"devDependencies": {
"nodemon": "^1.17.3"
}
}
1.0.7
First number (1
) :
1.5.0
to 2.0.0
means that it’s very probable to cause errors for updating to 2.0.0
from 1.5.0
Second number (0
) :
1.5.0
to 1.6.0
in terms of compatibilityThird number (7
) :
1.5.0
to 1.5.1
should not cause any errors^
:
npm i express@^1.1.1
installs a version from 1.1.1
~ 2.0.0
(excluding 2.0.0
because the first number has changed and it’s major (version) change)~
:
npm i express@~1.1.1
installs a version from 1.1.1
~ 1.2.0
^
is often useful than ~
because minor version update is compatible to the lower version and has the most updated functionalities
@latest
: used to install the most updated (latest) version of packages (can be expressed as npm i express@latest
or npm i express@x
npm outdated
commandnpm outdated
Current
& Wanted
is differentnpm update [PACKAGE NAME]
npm update
updates ALL packages to the version specified in Wanted
Compare packages
Check the download trend of package
Thank you for reading!
#nodejs #javascript #web development #programming