For Semantic Version is described elsewhere.
Documentation: https://yarnpkg.com/en/docs/
yarn init Spin up a new repo.
yarn install Install all packages listed in the package.json
file.
yarn add -D packageName Downloads the package and save in devDependencies
yarn remove -D packageName Uninstalls the package and removes from package.json
file.
npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you’re sharing.
Packages are just a folder containing reusable code. It will contain a package.json
file.
There are a lot of npm commands, but these are the most common a site developer will need.
Note: Before installing a package, it is a good idea to make sure npm itself is current. Issue:
npm update -g npm
npm install packageName
This will create the node_modules directory (if one doesn't exist yet), and will download the package to that directory when installing to a project. i.e. npm install package
If you are installing globally (npm install -g package
) then the package will probably be installed to /usr/local/lib/node_modules
. To find out for sure, run npm list -g --depth=0
Install your development tools globally. This is because if you need to run an npm package from the command line then it is recommended that you install it globally. Conversely, if you application uses require()
to include the package, then install it locally.
Note that if any package is already installed and satisfies the SemVer rule in package.json
, running npm install will not update it to the latest version, even if there is a newer one satisfying the same rule. In fact, no change is made to the package in this case, even if it was modified.
Thus, to reliably reinstall the latest versions of all packages satisfying the semver rules in package.json
, delete the node_modules folder and run npm install.
When saving to the package.json
file, npm will include the version number. You may want to double check that it specified it the way you want. Refer to the SemVer syntax if needed.
Run npm update
in the same directory as the package.json
file.
Run npm update -g packageName
To find out which packages need to be updated, you can use npm outdated -g --depth=0
.
Run npm uninstall packageName
npm uninstall -g packageName
npm list -g --depth=0
//this will show all global packages installed on your machine with version numbers. You will need to do this if installing packages such as Grunt.
npm init
npm install grunt --save-dev
npm install --save-dev grunt-babel
npm install --save-dev grunt-contrib-jshint