Node.js
Aboutβ
Node.js is an open-source, cross-platform, back-end, JavaScript runtime environment that executes JavaScript code outside a web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scriptingβrunning scripts server-side to produce dynamic web page content before the page is sent to the user's web browser. Consequently, Node.js represents a "JavaScript everywhere" paradigm, unifying web-application development around a single programming language, rather than different languages for server- and client-side scripts. (Wikipedia, 2020)
Getting startedβ
NVMβ
nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.
Installationβ
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Install latest node.js versionβ
nvm install node # "node" is an alias for the latest version
Install a specific version of nodeβ
nvm install 6.14.4 # or 10.10.0, 8.9.1, etc
The first version installed becomes the default. New shells will start with the default version of node (e.g., nvm alias default
).
List all available versionsβ
nvm ls-remote
User a specified versionβ
nvm use node # or 6.14.4, 10.10.0, 8.9.1, etc
Run nodeβ
nvm run node --version
Run node with specific versionβ
nvm exec 4.2 node --version
Get path where specified version was installedβ
nvm which 5.0
YARNβ
Yarn is a package manager that doubles down as project manager. Whether you work on one-shot projects or large monorepos, as a hobbyist or an enterprise user, we've got you covered.
Installationβ
npm install -g yarn
Accessing the list of commandsβ
yarn help
Starting a new projectβ
yarn init
Installing all the dependenciesβ
yarn
# OR
yarn install
Adding a dependencyβ
yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]
Adding a dependency to different categories of dependenciesβ
yarn add [package] --dev # dev dependencies
yarn add [package] --peer # peer dependencies
Upgrading a dependencyβ
yarn up [package]
yarn up [package]@[version]
yarn up [package]@[tag]
Upgrading a dependencyβ
yarn remove [package]
Upgrading Yarn itselfβ
yarn set version latest
yarn set version from sources