Install Node.js and NPM on Raspberry Pi

[1: Recommended] for 64-bit only. Raspberry OS 32-bit is already coming with Node-Red pre-installed

you will get:

  1. node.js and npm installed (LTS version)
  2. pigpio module
bash <(curl -sL

source: Running on Raspberry Pi : Node-RED

[2: Good]

To install node.js and npm without installing node-red or to update installed at step 1:

curl -sL | sudo -E bash -
sudo apt install -y nodejs

source: Beginner’s Guide to Installing Node.js on a Raspberry Pi

Good: this method could be used to fix most of problem with node+npm

Bad: Failed to install node-red if I’d have latest version installed

[3: Not recommended]

sudo apt -y install nodejs
sudo apt -y install npm

i’ve had a problem with npm (something like: “does not support node version installed”). So I  had to go back to [2]

[4: Test installation]

create a file (for example: nano test.js):

const http = require('http');

http.createServer(function (request, response) {
   // Send the HTTP header 
   // HTTP Status: 200 : OK
   // Content Type: text/plain
   response.writeHead(200, {'Content-Type': 'text/plain'});
   // Send the response body as "Hello World"
   response.end('Hello World\n');

// Console will print the message
console.log('Server running at');

and run from terminal

node test

start any browser and enter we address


if you see ‘hellow world’, everything works!!

Leave a Reply

Your email address will not be published.