NPM commands
Initialize
Initialize a new project:
powershell
$myVar = 'test'
npm init
This command initialize the new project with a package.json
file
Install package
Install a new package:
powershell
npm install packageName
A version or tags (@latest
, @next
) can be specified:
powershell
npm install packageName@latest
npm install packageName@next
npm install packageName@1.6.3
npm install packageName@2.0.0-alpha.5
Packages can be used only for development. Add the -D
or --dev
:
powershell
npm install -D packageName
npm install --dev packageName
Packages can also be installed globally, and then become available for all projects. Use the -g
modifier:
powershell
npm install -g packageName
List package
List packages:
powershell
npm list
List first level packages:
powershell
npm list --depth=0
List packages and their dependendies on n levels
powershell
npm list --depth=3
List the packages and view the result in JSON:
powershell
npm list --json
Outdated packages
List outdated packages:
powershell
npm outdated
TIP
To update the package, launch a npm install
command by specifying the wanted version of the package, eventually the @latest
version.
Remove package
Remove a package
powershell
npm uninstall packageName