Hmm, I don't know. I install Node.js from the official website using a .pkg, though. Maybe also try using "su" or "sudo" to run the commands? My output is like this:
(zsh-1) kinky-dungeon % mkdir ~/Electron
(zsh-1) kinky-dungeon % cd ~/Electron
(zsh-1) Electron % ls
(zsh-1) Electron % npm install electron --save-dev
added 75 packages in 3s
21 packages are looking for funding
run `npm fund` for details
(zsh-1) Electron % ls
node_modules package-lock.json package.json