Install nvm

Install or update nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash

If zsh complains about insecure directories, ignore the warning and continue:

compaudit | xargs chmod g-w

Install the latest LTS node.js

List available remote versions:

nvm ls-remote

Install the Latest LTS version:

nvm install 20.11.1
npm update -g

Verity that node.js is installed and ready to use:

node --version

Install essential npm global packages

npm i -g typescript eslint typescript-language-server ts-node

To update node.js and install globally installed packages:

nvm install 20.11.1 --reinstall-packages-from=20.10.0

To check globally installed npm packages:

npm list -g --depth=0

To update globally installed packages

npm update -g

Troubleshooting

If your node version keeps reverting back to a specific old version after nvm use, check the nvm alias setting inside ~/.nvm/alias/default (It is safe to delete this file.).

Install Emacs lsp-mode

Make sure lsp-mode and tide-mode Emacs packages are installed & configured.

Run M-x lsp-install-server and select ts-ls, it will result in the following commands being executed:

npm i -g typescript-language-server
npm i -g typescript