Node.js

  • Node.js is
    • cross-platform: can run on Windows, Linux, Unix, macOS, and more.
    • a back-end JavaScript runtime environment
      • runs on the V8 JavaScript Engine
      • executes JavaScript code outside a web browser.
    • lets developers use JavaScript to
      • write command line tools and
      • for server-side scripting.
        • The ability to run JavaScript code on the server is often used to generate dynamic web page content before the page is sent to the user’s web browser.

nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

command description
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash install nvm (see github)
nvm ls Find out which versions of Node.js you may have installed and which one of those you’re currently using
nvm ls-remote List all versions of Node.js available for installation (for Windows: nvm ls available)
nvm install 8.1.0 install Node.js v8.1.0
nvm install 8.1.0 --latest-npm install Node.js v8.1.0 and update npm
nvm install-latest-npm update current npm (get the latest supported npm version on the current node version)
nvm use 4.2 Choose version. Here: set v4.2.0 as the active version
nvm alias default 16.14.2 set default node.js version 16.14.2
nvm alias default lts/iron  

npm

Node Package Manager.

command description
npm help some-command official doc, eg. npm help start
npm i -g npm Do not run this! Use nvm instead. Update npm.
npm install (in a package directory, no arguments) Install the dependencies to the local node_modules folder (which will be created if it does not exist). In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package. By default, npm install will install all modules listed as dependencies in package.json.
npm install see doc
npm Uninstall pkg Uninstall a package
npm init this tells npm to make a file in your folder called package.json that is going to help you organise these dependencies.
npm start This runs a predefined command specified in the "start" property of a package’s "scripts" object. If the "scripts" object does not define a "start" property, npm will run node server.js. (Warning: sometimes Firefox does not update page changes (eg. when replacing the favicon with a different favicon that has the same file name). In this case you have to clear the site data under “Privacy & Security” → “Cookies and Site Data” → “Manage Data” → search for your website → “Remove Selected” and then reload the page.)

Semantic Versioning

  • watch
  • read

  • New package versions may contain different “kinds of updates
    • “patch”
    • “minor release”
    • “major release”
  • SemVer is a way to communicate
    • as a package publisher:
      • to indicate in the SemVer version number which of the above “kinds of updates” the new published package version contains
    • as a package user:
      • to limit via the SemVer version number which “kind of package updates” will be accepted when we update dependencies

npx

npm install -g npx