This script will work on any Debian-based operating system, including Ubuntu and Diet-Pi. You may need to run sudo apt-get install build-essential first to ensure npm is able to build any binary modules it needs to install.
Selecting previously unselected package libhttp-parser2.7.1:amd64.
Preparing to unpack .../libhttp-parser2.7.1_2.7.1-2_amd64.deb ...
Unpacking libhttp-parser2.7.1:amd64 (2.7.1-2) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_8.10.0~dfsg-2ubuntu0.4_amd64.deb ...
Unpacking nodejs (8.10.0~dfsg-2ubuntu0.4) ...
Setting up nodejs-doc (8.10.0~dfsg-2ubuntu0.4) ...
Setting up libhttp-parser2.7.1:amd64 (2.7.1-2) ...
Setting up libuv1:amd64 (1.18.0-3) ...
Setting up libc-ares2:amd64 (1.14.0-1) ...
Setting up nodejs (8.10.0~dfsg-2ubuntu0.4) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto $
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
sudo: npm: command not found
ok - so re-run - sudo apt-get purge nodejs
then which node to check it's been removed.
then - sudo rm /etc/apt/sources.list.d/nodesource.list
to clear out the old nodesource repo (if it was there) then re-run
try a sudo apt update && sudo apt upgrade manually first and accept the change
then redo the nodejs install
(have to go out for an hour or so - back in a bit) (but we are in google the answer territory now..)