We can start a project by running
We can also do
npm init -y if we want a default package.json.
You can fetch NPM packages in two ways. The first way is by directly accessing the NPM website. The second way is using the NPM CLI:
1 npm search <package>
A very important NPM command is install. It allows us to add dependencies to our project.
Some use cases:
1 2 3 4 5 6 npm install # install the packages specified in package.json npm install package # install a package npm install email@example.com # install a specific version npm install package@latest # install the latest version npm install package -D # install as development dependency npm install -g package # install package globally
We can uninstall a package using uninstall:
1 npm uninstall package
We can update packages using update:
1 2 npm update // update packages npm update package // update a specific package
We can still list outdated packages by doing:
1 npm outdated
Some other commands that can be useful when we are working with NPM:
1 2 3 4 npm login # log in npm logout # log out npm whoami # display logged in user npm publish # publish a package