Skip to Content
Technical Articles

The Smallest Host to Run a CAPM-based Node.js Application

Intro

SAP Cloud Application Programming Model (CAPM) introduces abstraction and segregation of layers that compose a full-stack application and unifies tools that are used to model the application, however leaves a freedom of choice of technology stack for implementation (having said that, Java and JavaScript are natively supported and benefit from tooling and libraries/modules that has been built for them in order to streamline application development). DJ Adams and Maximilian Streifeneder do really great job by continuously sharing hands-on materials on this topic, where they pay significant attention to how CAPM can be applied when developing Node.js applications by putting theory into practice – have a look into a summary of episodes and check out live stream episodes if you haven’t done so yet to learn more about CAPM, tooling and practical hints on how to make effective use of them. This blog is inspired by DJ’s and Max’s knowledge sharing sessions and is here to challenge a subject of hosting a Node.js application developed following CAPM concepts. In sake of simplicity, I will use a sample demo application – SAP Event Registration app backend – throughout the blog, so we will not develop or extend any applications here, but will focus on deploying and running them in a very specific environment. To put it differently, this blog doesn’t address a question of HOW to develop a Node.js application and how to use CAPM, neither it addresses a question of WHAT to develop, as the application has already been developed – instead, we will look into WHERE to deploy the application and where to run it. Local machine? On-premise server? Cloud platform? Let’s bring sense of challenge and fun to this – what is the SMALLEST platform that you can think of and that we can use to run such a Node.js application developed using CAPM and how straightforward it is to make this happen?

I will not explore highly specialized platforms – instead, I’m going to put under test an affordable, general purpose, lightweight single-board computer – Raspberry Pi. To make a test more challenging, I’m not going to use the latest, more advanced and powerful models (such as Raspberry Pi 3), but will use the smallest and the least powerful model – Raspberry Pi Zero W. This is a very tiny microcomputer – it is smaller than a credit card (is dimensions are 65 mm x 30 mm x 5 mm), its weight is just 9 g and its price at the time of writing of this blog is below £10:

 

Hold on for a moment. Before we progress further and step into setup and configuration details, you might be wondering about practical usage of such a setup and rationale behind running this kind of Node.js applications on Raspberry Pi, especially considering that the application could have been set up and executed locally on a laptop or pushed to a (trial) account of SAP Cloud Platform and started there in a matter of few clicks. Don’t get bothered about that – there is no practical usage (or at least not anything close to it that I could think of – if you find one, please share it in comments) – it all has been done just for fun, and the only purpose was to see if a tiny single-board computer can cope with running a simple cloud-ready Node.js application created on basis of CAPM principles in the days of powerful developer laptops and widely used cloud platforms. And you should remember about a challenge component that was set earlier – we are looking for a smallest possible and yet affordable platform, not the most powerful, scalable, feature-rich, etc. With this in mind, let’s move on to technical aspects now.

 

Operating system and network access setup

Since Raspberry Pi is shipped as bare metal, we firstly need to install an operating system. I use Raspbian Stretch – to be more precise, its minimal image – Raspbian Stretch Lite, so that Raspberry Pi can be operated in a headless mode. I followed standard instructions available at the manual on installation of operating system images to write an image.

The next step is to connect Raspberry Pi to a Wi-Fi network and enable SSH on it so that it can be accessed from a laptop – configuration steps are described at the manual on setting up a Raspberry Pi headless.

Upon completion of above steps, Raspberry Pi can be powered on and if everything has been set up correctly and the device got connected to the network, Raspberry Pi shall become discoverable, and we can proceed to setting up SSH connection, remotely logging into Raspberry Pi, changing a default password for a built-in user ‘pi’, and running the rest of configuration steps described below using the terminal.

 

Environment and runtime setup

Let’s start from installing Git – this will be handy when cloning a repository that contains the Node.js application later:

sudo apt install git

This step above is optional – we can omit it and obtain application in a number of alternative ways: clone a repository to a laptop and copy it from a laptop to Raspberry Pi via SSH (SFTP), download content of a master branch of a repository in a ZIP file using cURL and unzip it.

Next, we need to install Node.js runtime. I’m going to install latest compatible version, so I will not install it from a repository, but will go through manual installation.

Before downloading Node.js distribution, we shall figure out which distribution we are going to use. To do so, we firstly check CPU architecture of Raspberry Pi:

less /proc/cpuinfo

As it can be seen, this model of Raspberry Pi uses ARM v6 architecture. We can now navigate to a list of Node.js distributions and find a compatible one. Node.js v12 requires at least ARM v7, so it is not compatible with Raspberry Pi Zero W, whereas Node.js v11 is compatible with this Raspberry Pi model. I plan to use the latest compatible distribution, so we are going to download and install Node.js v11.15.0:

curl -O https://nodejs.org/dist/latest-v11.x/node-v11.15.0-linux-armv6l.tar.xz

Remaining steps are a simplified version of instructions available at the manual on installation of Node.js via binary archive:

sudo mkdir -p /usr/local/lib/nodejs

sudo tar -xvf node-v11.15.0-linux-armv6l.tar.xz --strip-components=1 -C /usr/local/lib/nodejs

rm node-v11.15.0-linux-armv6l.tar.xz

Add location of Node.js binaries to an environment variable PATH permanently by appending user specific shell initialization script (~/.profile):

Refresh ~/.profile:

. ~/.profile

 

Before diving into subsequent steps of installation procedure, given it will involve installation of global Node.js modules, we need to ensure that the user has sufficient privileges for Node.js binaries and global modules location – we can change privileges to a corresponding directory and its subdirectories, or alternatively, change ownership for it:

sudo chown -R $USER /usr/local/lib/nodejs

 

Node.js runtime is now installed and ready. Optionally, we can install tools for system monitoring – such as package sysstat or nmon – to complement built-in tools for a more comprehensive system workload analysis.

 

Application setup

Remaining steps are to download and install the Node.js application – for this, we are going to use installation instructions available at GitHub repository of the application.

Firstly, CDS module is installed globally from SAP NPM registry:

npm set @sap:registry=https://npm.sap.com

npm install -g @sap/cds

Next, obtain, install and deploy the Node.js application:

git clone https://github.com/sapmentors/sitregcapm.git

cd sitregcapm

npm install

npm run build

npm run deploy

 

Action!

Finally, we are ready to start the Node.js application:

npm start

 

The application is up and running – and we can now access it remotely (for example, from the laptop) using a browser or an HTTP client to execute queries to its APIs:

2 Comments
You must be Logged on to comment or reply to a post.
    • Hi Gregor,

      It is an issue that I haven’t faced when setting up my Rapsberry Pi Zero W – thank you for this valuable comment and notes. It looks to me that it might be OS version specific – in Raspbian Stretch (not sure about earlier revisions of it, but at least in the one I used – Raspbian Stretch (2019-04-08) Lite), Wi-Fi configuration in headless mode might have become simpler. I used Raspbian Jessie in the past, but it was on Raspberry Pi 2 Model B and I used a standard (not Lite) edition of Jessie there, so network configuration was done in GUI mode, with keyboard and monitor connected to Raspberry Pi. Only now for Raspberry Pi Zero W, I needed a lighter edition – and here Raspbian Lite became handy, but by time I got to it, the current version of Raspbian was already Stretch.

      I now downloaded Raspbian Jessie (2017-07-05) Lite and tested the same configuration I used for Raspbian Stretch, when setting up Raspberry Pi Zero W – and was able to reproduce the problem you mentioned: Raspberry Pi didn’t get discovered on the network. Following the thread on this error that you mentioned, I’ve extended configuration by adding file interfaces with the suggested content and leaving the rest of configuration (precisely, wpa_supplicant.conf for Wi-Fi connectivity with exactly same content as used before), and then it all worked and Raspberry Pi got discovered on the network.

      Glancing through Raspberry PI forum threads, I can find some that mention a similar issue in Raspbian Stretch as well, but they (such as this) date back to the year 2017, so might be the same issue existed in earlier revisions of Raspbian Stretch, too.

      Anyways, it is good to know about that additional interfaces configuration – thank you for pointing it out.

      And thanks for the application – it was a good available example that I could make use of when preparing materials for this blog.

      Regards,

      Vadim