SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

SAP HANA XS Advanced, Creating a Node.js Module

Creating a Node.js Module and implementing XSJS and XSODATA

Overview

🎓 beginner 15 min. SAP HANABeginnerOdataExpress Edition
Thomas Jung T Thomas Jung November 1, 2022
Created by September 19, 2016
Contributors

Prerequisites

Prerequisites

Steps

Next Steps

Time to Complete

15 Min.


Step 1 Create a Node.js module
โ€”

Like the previous exercises, you will start by creating a new module. New->Node.js Module

New Module
New Module

Name the module core_xsjs and press Next.

js module
js module

Be sure to check the box Enable XSJS support. Then press Next. Then press Finish.

XSJS support
XSJS support

Once again the mta.yaml file has been extended to add the core_xsjs module.

MTA module updated
MTA module updated

This XSJS module will also need the UAA service for authentication. Additionally, it will need data from the database module and the HDI container behind it. Add those dependencies to the node module

MTA module updated
MTA module updated

Now you need to add the dependency from the web module to this new Node.js module and a destination route to it as well.

In the Requires section of the web module, add core_xsjs_api

If you are editing this manually, this should match the name of the value under Provides in the new node module

MTA module updated
MTA module updated

Add destinations in the field group and the following key-value pairs as the properties for the core_xsjs_api module:

Code
name: core-xsjs-backend
url: ~{url}
forwardAuthToken: true

The complete section for the web module should now look like this:

MTA module updated
MTA module updated

What is this configuration for?

The approuter is a module that serves as a single point of entry to a Multi-Target Application. In this case, the web module contains the call to this module in the package.json file. The approuter will use routes to determine the destination for a request coming from, for example, a web browser. The configuration you have just entered is naming the Node.js destination as core-xsjs-backend, URL is picking up the value from the provides URL, which is in turn taking it from the reserved environment variable, default-url.

Later at deploy, the destination routing builds a dependency and navigation ability between the two services without ever having to hard code the URLs or ports. They are assigned at deploy time and all references are automatically updated.

Save the yaml file and go into the code editor. Copy the definition of the node module in the validation below:

MTA module updated
MTA module updated

Step 2 Configure Routes
+
Step 3 Enable authentication in your service
+
Step 4 Create an OData service
+
Step 5 Create an XSJS service
+
Step 6 Execute the xsjs module
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 6
1. Create a Node.js module 2. Configure Routes 3. Enable authentication in your service 4. Create an OData service 5. Create an XSJS service 6. Execute the xsjs module

Learn more →