Node.js nvm, npm tricks

Table of Contents

nvm

Install: /nvm-sh/nvm#install--update-script

Command
Action
nvm ls see the Node.js versions you have installed via nvm
nvm install --lts install LTS version (Long Term Support) — recommended for most users and production environments because it is more stable
nvm alias default 'lts/*' set the LTS (Long Term Support) version as your global default so it persists across new terminal sessions

npm

~/.zshrc:

# Initialize zsh completion system
autoload -Uz compinit
compinit

# Enable npm link completion for scoped packages
_npm_link_completion() {
  local -a pkgs
  pkgs=($(
    {
      find -L "$(npm root -g)" -mindepth 1 -maxdepth 1 -type d ! -name "@*"; \
      find -L "$(npm root -g)/@"* -mindepth 1 -maxdepth 1 -type d; \
    } | sed "s|$(npm root -g)/||"
  ))
  _describe 'npm packages' pkgs
}

# Enable completion for 'npm link'
compdef _npm_link_completion npm link

See also:

Base 11ty npm scripts via npm workspace

This package provides a pre-configured do folder setup that helps organize your development workflow using npm workspaces. The do folder contains scripts for building and running your Eleventy project.

Installation:

  1. Install /anyblades/eleventy-blades to reuse pre-defined 11ty scripts from there:
npm install @anyblades/eleventy-blades
  1. Create a helper folder do to symlink the do/package.json within:
mkdir do
cd ./do
ln -s ../node_modules/@anyblades/eleventy-blades/src/do/package.json
  1. Finally register do folder as npm workspace in your root package.json:
{
  ...
  "workspaces": ["do"],
  "scripts": {
    "start": "npm -w do run start",
    "stage": "npm -w do run stage",
    "build": "npm -w do run build"
  },
  ...
}

Done! 🎉 Now you can run:

Living examples:

Benefits: