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
npm link auto-completion with @namespaces support
~/.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:
- Install
/anyblades/eleventy-blades to reuse pre-defined 11ty scripts from there:
npm install @anyblades/eleventy-blades
- Create a helper folder
doto symlink thedo/package.jsonwithin:
mkdir do
cd ./do
ln -s ../node_modules/@anyblades/eleventy-blades/src/do/package.json
- Finally register
dofolder as npm workspace in your rootpackage.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:
npm startto start 11ty dev server with live reload and Tailwind watch modenpm run stageto build and serve production-like site locallynpm run buildto finally build the site for production- all available scripts:
/anyblades/eleventy-blades/blob/main/src/do/package.json
Living examples:
Benefits:
- Clean separation: Keep build scripts separate from project configuration
- Reusable workflows: Update scripts by upgrading the package
- Workspace isolation: Scripts run in their own workspace context
- Easy maintenance: No need to manually maintain build scripts