Node.js
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Installation
Using Homebrew
Manage multiple Node Version with nvm
Download and install nvm by running:
Then download Node and select your version by running:
See the documentation for information.
Switch automatically the Node and NPM version
Make sure you have set the default
alias for nvm - e.g.: nvm alias default 8.11.2
Add nvm-auto
to your plugins in ~/.zshrc
.
Add a call to the nvm_auto_switch
function after NVM is initialized in your .zshrc
file.
Source .zshrc
in your current shell or restart your shell.
npm usage
To install a package:
To install a package and save it in your project's package.json
file:
To see what's installed:
To find outdated packages:
To upgrade all or a particular package:
To uninstall a package:
npm-link
Symlink a package folder:
Yarn
For project with a lot of dependencies, or particular dependencies, we should probably use yarn.
Homebrew
You can install Yarn
through the Homebrew. This will also install Node.js
if it is not already installed.
If you use nvm or similar, you should exclude installing Node.js
so that nvm’s version of Node.js
is used.
Path Setup
If you chose manual installation, the following steps will add Yarn to path variable and run it from anywhere.
Note: your profile may be in your .profile
, .bash_profile
, .bashrc
, .zshrc
, etc.
Add this to your profile:
export PATH="$PATH:/opt/yarn-[version]/bin"
(the path may vary depending on where you extracted Yarn to)In the terminal, log in and log out for the changes to take effect
To have access to Yarn’s executables globally, you will need to set up the PATH
environment variable in your terminal. To do this, add export PATH="$PATH:`yarn global bin`"
to your profile.
Upgrade Yarn
Yarn will warn you if a new version is available. To upgrade Yarn, you can do so with Homebrew.
Test that Yarn is installed by running:
Problems? If you are unable to install Yarn with any of these installers, please search through GitHub for an existing issue or open a new one.
Usage
Now that you have Yarn installed, you can start using Yarn. Here are some of the most common commands you’ll need.
Starting a new project
Adding a dependency
Adding a dependency to different categories of dependencies
Add to devDependencies
, peerDependencies
, and optionalDependencies
respectively:
Upgrading a dependency
Removing a dependency
Installing all the dependencies of project
or
Install globally some useful packages
Additional Reading
Last updated