Node Js Backend – Raspberry Pi 2 32bit Problem
Recently, I have started working on a side project for a non-profit organisation. They needed a volunteer management app for handling help requests and notification of the deliveries to volunteers. After some initial research and some discussions with the project manager ChatGPT, I came up with this awesome todo list:
- Create backend server and API using Node js
- Write an app using Flutter with Dart.
I know it is a very comprehensive list πLet me be clear, my only exposure to the web development was more than 10 years ago and it was just one uni course on php development. So I didn’t have a clear idea on how the steps would shape up. Now that is out of the way, I needed to learn and quickly develop the first prototype. You can see my awesome, beautiful mess of a spaghetti code here: https://github.com/yusuftas/team_volunteer
First step was to start working on the backend. I got ChatGPT to build me the first version of the backend: user authentication API. Since I don’t have any experience in web development, I had no idea if the code was good or not, but it was something to start with. I had many troubles getting the code to work and almost gave up using ChatGPT, but that is a topic for another time. You can see the code in my github repo I linked, but just to give a context to this blog post, I will summarize the code:
- Defines the user model as I requested: username, password and user role (admin or general)
- It uses MongoDB to store users in the database.
- Auth API receives requests for registering or logging in with username and password
- If registering, Auth API stores the new user info in the database, if logging in it retrieves the user from database and compares password hash for authentication.
This is roughly all it does for now. Hopefully as I progress, I will document my learning journey here. I have already encountered many problems and learned many stuff along the way in just one week, raspberry pi 2 being 32bit was the worst of this week’s problems.
Finally I am getting to the topic. So you see, I needed to host a server and keep it possibly running non-stop. I didn’t want to start paying for hosting this server while still learning web development, and I just remembered I had one raspberry pi 2 waiting to be used in my forgotten electronics bag. It was a perfect candidate, at least I thought, easy to plug in to power and keep it running non-stop, no fan or noise, low power. But there was one problem: it had a 32bit CPU: armv7l
It never actually occurred to me that this would be a problem. I knew my raspberry pi was old but it had enough ram and power to run a Ubuntu server. I didn’t question the CPU architecture though, given the mongodb is a tool to handle very large datasets, maybe I should have seen this coming. It seems at some point in the past, MongoDB has decided to drop support of 32bit builds as mentioned in this question:
I found the issue when trying to install the package through package manager. Adding the repositories and everything worked fine, until I started getting package not found errors:
Then I started digging it down and found the core problem, my raspberry pi 2 had 32bit CPU πππ. If you also didn’t know this and want to figure out your CPU architecture:
1 |
cat /proc/cpuinfo |
ARM added support of 64 bit instruction set in armv8. It is important to note that even if you have 64bit CPU, you can still install 32bit OS on it. This would still cause problems! If you are using raspbian make sure you use 64 bit version, in the past there was no 64 bit raspbian but this is no longer the case: https://www.raspberrypi.com/news/raspberry-pi-os-64-bit/
So we know the problem, but what is the solution? Solution is stash that raspberry pi back to where it was π Unfortunately there is no proper way of running MongoDB on this or earlier raspberry pi models. You will either need to change your projects’ needs to use some other database you can use in 32bit pi, or change where you host your server. I decided to go with the latter. I am now running the mongodb in a docker container on my laptop, and actually it is very easy to do so with docker:
1 |
docker run -d -p 27018:27017 mongo |
Port numbers are dependent on your project setup. This will fetch the mongo docker image from the docker’s servers and you will be able to run and access the docker on the specified port, in my case 27018. So for example I am accessing the mongodb with this URI: mongodb://127.0.0.1:27018/database_name
TL;DR : Raspberry pi 2 being an old model uses 32 bit CPU, which prevents installing MongoDB. After I couldn’t run my Node js + MongoDB backend server on my Pi 2, I moved to using docker containers on my laptop for the time being.
This is not the end of this journey though, it is just the beginning. It will probably take me a lot of time to get this project to finish, I will need to learn a lot of new stuff along the way. Hopefully, there will be a lot more posts about how I do stuff weirdly in this project, so stay tuned for that I guess. Until then, keep learning!