Node.js is a JavaScript runtime environment built on Google Chrome’s V8 engine. It allows you to run JavaScript code on the server, making it easy to develop web and network applications without having to use another language for the backend.
Some of the key features of Node.js are:
- Asynchronous and non-blocking: Node.js uses a non-blocking I/O model, which allows it to handle multiple simultaneous connections without one operation interfering with another.
- Event-driven: It uses an event system to manage operations and respond to events, making it ideal for real-time applications.
- Package management: Node.js comes with
npm(Node Package Manager), which simplifies the installation and management of packages and dependencies. - Scalability: It is ideal for applications that require high scalability and network performance.
If you need more information about Node.js, here’s a link to the course 👇
Learn to develop with Node.js step by step
Having Node.js on a Raspberry Pi can serve many purposes. For example, you can develop web applications and APIs directly on your Raspberry Pi, create scripts to automate tasks, or control devices connected to the Raspberry Pi.
So let’s see how to install and run Node.js on Raspberry Pi.
How to Install Node.js on Raspberry Pi
Make sure your Raspberry Pi is updated before starting the installation. Run the following commands to update packages and the operating system:
sudo apt update sudo apt upgrade
NodeSource is a repository that provides updated versions of Node.js that can be easily installed on Raspberry Pi. We will use their repository to install Node.js.
To add the NodeSource Repository, we first need to install curl if it’s not already installed:
sudo apt install curl
Then, use curl to download the installation script from the NodeSource repository:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
Note: The 20.x in the URL refers to the version of Node.js we are installing. You can change it to your preferred version.
After adding the repository, install Node.js with the following command:
sudo apt install -y nodejs
This will install both Node.js and npm (Node Package Manager).
Develop a Simple Application
To test that everything is working, we can create a basic example. Create a file called app.js:
nano app.mjs
Then, add the following code to the app.js file:
import { createServer } from 'node:http';
const server = createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello from LuisLlamas.es!\n');
});
// starts a simple http server locally on port 3000
server.listen(3000, '127.0.0.1', () => {
console.log('Listening on 127.0.0.1:3000');
});
Now run the application with
node app.mjs
Open a web browser and visit http://localhost:3000. You should see the message “Hello from LuisLlamas.es!”.

