Node.js is a very versatile and powerful platform and it can represent a very interesting starting point to create web and mobile applications both on premise and in the cloud. If we also add the agility of building these applications through the NPM ecosystem (the largest software registry in the world) we have a huge potential for building software solutions. If we add to this potential the ease of extracting information from our SAP systems through existing (or new) Function Modules (exposed through RFC), we obtain the power to speed up the creation of business applications with high responsiveness and an excellent user experience.
It is very interesting that in recent times SAP is officially recognizing the potential of Node.js. This is through the possibility to develop SAP HANA native applications with Node.js and XS Advanced. But, what if I still don’t have a SAP HANA enabled system? Well, there is an interesting alternative that we can use here, so we can still benefit from the power of Node.js to build applications on top of SAP systems: the node-rfc connector.
With the node-rfc connector we can basically connect to any standard, existing or new ABAP function module given it is RFC enabled and use the output of this FM to expose it to the world through Node.js.
We can then use Node.js to create RESTful API’s for example and even create our front end applications there.
Here is an example architecture we have used to achieve this kind of applications:
Main advantages from this architecture
Some of the main advantages we have found while using this architecture are:
- Flexibility to expose the information after the Node.js layer
- Small response times
- Reliability and stability for application execution
- Create a code base (Node.js code) that can later be reused once we migrate our system to SAP HANA
Now, let’s review how we can make the connection happen:
Connecting Node.js with SAP
To begin with, as we said before, we will be using the node-rfc component.
According to the documentation, a pre-requisite for the installation is to download the SAP NW RFC Library that works as the intermediary between the node-rfc component and the FM RFC enabled from SAP. (In order to download this component we will require an SAP S-User so we can access the SAP Marketplace software download section).
Once we have downloaded the SAP NW RFC Library and we have installed it we can proceed with our example (Instructions for the installation are present within the links), we will just add this tip:
By default, the node-rfc component gets installed inside the directory that corresponds to the installation platform (for example win32_x64). This can causa an error by the time we are executing the application because the node-rfc component expects it to be located inside the \rfc directory directly. To solve this possible problem we just need to move the location of the file to the \rfc directory as we can see in the image bellow:
Once that we have this pre-requisite installed, we can proceed to create a sample node.js project, and after that we proceed to add the node-rfc module to our new project as well:
npm init noderfcsample
npm install node-rfc
As we can see, the connection code is simple 🙂
We first create a client with the abapSystem details. Next, we stablish a connection to SAP by using the client.connect method. After the connection is successful we call the RFC enabled FM with client.invoke.
After we run our project, we can see the following response in the console:
Our example for this post is very simple indeed, but it opens a lot of possibilities as we have discussed before. We can enrich our code with one Node.js backend framework such as SailsJs or Express and have a fully functional REST API quickly.
From there we can use one of the many front end technologies available to create Web or Mobile apps (SAPUI5, React, Angular for web for example or a Native app, the brand new SAP Cloud Platform SDK for Android or for iOS, Flutter or React Native). So many possibilities!
Well, I hope you have enjoyed this blog post and that it can be useful for your next projects. Let us know in the comments what applications you are working with or in case you have any doubts let us know and we will try our best to help you!
Thanks a lot!