Results: 44
Installs package
npm install  /  npm i
Shows current version of
npm
npm --version  / npm -v
Creates
package.json
file with default values
npm init --yes  /  npm init -y
Installs package
moment
npm install moment --save  /  npm i moment -S
Installs package
lodash
for
dev environment
npm install lodash --save-dev  /  npm i moment -D
Installs package
live-server
globally so that other apps can use it
npm install --global live-server  /  npm i -g live-server
Other shortcuts - https://docs.npmjs.com/misc/config
Deletes all packages from
node_modules
that are extraneous packages (that are not listed in
package.json
)
npm prune
Before running the above command,
npm list --depth 0
showed several packages as extraneous. Extraneous are packages that are not listed in
dependencies
or
devDependencies
but installed in
node_modules
)
+-- gulp@4.0.2 extraneous
+-- gulp-sass@4.1.0 extraneous
`-- moment@2.27.0
Installs exactly the specified version of the module
npm install moment@2.25.2
Installs the specified module with the latest
patch
npm install moment@2.25
Installs the specified module with the latest
minor
and
patch
versions
npm install moment@1
Installs the latest version of the module (with latest
major
,
minor
and
patch
versions)
npm install moment
Only
major
version will stick to
1
but
minor
and
patch
will be the latest versions
"dependencies": {
    "moment": "^1.6.2"
}
Only updates
patch
but
major
and
minor
will be the specified versions
"dependencies": {
    "moment": "~1.6.2"
}
Exactly the specified version
1.6.2
will be installed
"dependencies": {
    "moment": "1.6.2"
}
The latest version of the package will be installed
"dependencies": {
    "moment": "*"
}
Shows globally installed modules
npm list --global --depth 0
Shows all packages without their dependencies (only top level)
npm list --depth 0
Shows all packages with only their dependencies (one level deep)
npm list --depth 1
We can run scripts that are listed in
scripts
key, inside
package.json
file. If the content is the following
"scripts": {
    "start": "node app.js",
    "server": "live-server"
}
Then we can run
npm run start
and npm will run
node app.js
We can also run
npm run server
and it will run
live-server
Deletes manually set default license (default license will become
ISC
)
npm config delete init-license
Deletes manually set default author name (default author will become empty string)
npm config delete init-author-name
Main properties / parameters that the file includes:
name
- name of the app (default is the name of the current folder)
version
- version of the app (default is 1.0.0 - major.manor.patch)
description
- short description for the project
main
- entry point - main JS file
keywords
- keywords that the app is related to
author
- project author
license
- default is ISC (Internet Systems Consortium)
Shows all the different ways we can use
npm install
command (in console)
npm install -h
Alternative to the above command
npm install --help
Results: 44