on ‎2020 Sep 10 1:39 PM
Hi, I am trying build a MTA application in cloud foundry. As I am very new to SAP and cloud Foundry with the basic knowledge, I have the following doubts
1. As my application is quite big and has many modules. Should I created seperate node js module for each modules in my application.
2. how do I use a function or a file from one node module in another.
Thanks you.
Request clarification before answering.
Hi,
the answer to your first question is a clear yes. You can have as many node apps/modules in one MTA project as you want. That is the idea behind a microservice architecture.
I would not advise using a function/file from another module. Each module should be separated from each other and different modules should only communicate on an HTTP service-level with each other.
In case you want to reuse code, you should make use of so-called node.js packages (sometimes they are also called modules but I won't use this term here to avoid a confusing with the MTA modules). Such a package can be added as a dependency to each of your MTA modules.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marius,
Thanks you for the quick response, that was really helpful.

The above screenshot shows my sample project structure "node_module" and "node_module_2" are the nodejs modules.

In the above screenshot "node_module_2" I have created a xsjs library called "type.xsjslib"

In the above Screenshot, "index.xsjs" file you see is of module "node_module", here I am trying to import and use the "test.xsjslib" which is present in the "node_module_2".
But I am getting the error "returning status 500: Library "node_module_2.type" not found"
NOTE: I am calling the "index.xsjs" file of "node_module" from web module.
1. Can you please help me in understanding this. If the way I am importing "type.xsjslib" library is wrong\not possible, How do we do it then.
2. How can I add a package/library as dependency to another module.
Thanks you!
Oh, you are using XSJS modules? May I ask why you are doing that? I'm not too familiar with XSC and I'm not sure if my answer would hold in this case as well. In case you run on XSA, I would recommend that you use plain Node.js modules as they are the way forward.
I'm afraid the full explanation will go beyond a single thread here. Here's a post that explains how you can publish a package to the public npm registry. In case you don't want to make your code Open Source, you can also prefer a private registry. In either way, I would switch to the SAP Business Application Studio to do these things.
In case you don't want to switch the IDE or to make your code public, you can always use export/require to organize all the reuse code in one file (per module). If you want to do this, you need to copy the same file to both modules and keep them manually in sync. That' not 100% clean but it will still save you a lot of work.
Thanks a lot Marius! That was really helpful.
Hi Marius,
I was wondering if I could clarify the point regarding communicating between modules. When you say "service-layer" does this mean the only way to have two modules communicate (in a microservices architecture) is to have them send HTTP requests over the Internet? Or is there a way to bind the two modules and have them communicate directly/in a localhost-like fashion?
Thanks!
Hi,
No, there are more ways. When talking about microservice architectures in general, there can be internal routes for this communication. But as of today, there are no internal routes available in SAP's CF distribtion.
If you do not want to expose an HTTP interface, you can use messaging services to send async/sycn messages between apps. The name of this service in SAP CF is Enterprise Messaging
| User | Count |
|---|---|
| 14 | |
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.