cancel
Showing results for 
Search instead for 
Did you mean: 

CDS Watch on Standard NodeJS project

06-30-2020 7:10 PM
2574 views 4 comments
0 Likes
SAP Managed Tags
Subscribe

Hi All,

I have 2 service layers in CAP project. One service layer is a CDS based service layer and another is Express based service layer (Both are NodeJS). The project structure is somewhat like this:

db
- data-model.cds

srv1
- x.cds
- x.js

srv2
- server.js

  1. How can I have CDS watch look for srv2 folder and expose it as a service?
  2. Can my srv2 service call the cds entities as belows:
    const {X} =cds.entities('my.perstlayer');

Thanks,

Harish

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

klaus_kopecz
Advisor
Advisor

Hi Harish,

You can change the CAP configuration for standard folders in your package.json. In your case add something like

  "cds": {
    "folders":{"srv": "srv1/"},

...

This will change the default "srv/" for the service folder to "srv1/". "cds watch" is now listening to srv1/.

Similarly, you can change the defaults for "db/" and "app/". Just enter the "cds env" command (or "cds env ls folders")

to check the effective configuration.

Former Member
0 Likes

Hi wattnu ,

Then can I not have 2 services layer and 2 UI5 (App) layers in the same CAP project?

Thanks,

Harish

klaus_kopecz
Advisor
Advisor
0 Likes

Not sure what you mean by "layers". Maybe you are fine with setting

"folders":{"srv": "srv2/"},

and within your server.js, load and start the services from srv1/ "manually" using the CDS API (https://cap.cloud.sap/docs/node.js/api)

jhodel18
Active Contributor
0 Likes

Hi Harish,

There are multiple functionalities delivered to you when you invoke the CLI command CDS watch.

First is that nodemon is invoked -- this is the node module responsible for listening to your changes in javascript and cds files.

Second is the invoking of cds run command. cds run command is heavily reliant on your CAP Model project and hence you can't use this in your regular express based node module.

I'm guessing you wanted the capability of nodemon available to your regular node module project? If that's the case then just setup the "start" script of your express based node module with nodemon -- below is my usual setup:

"dev": "nodemon ./server.js",

And of course, you need to have nodemon as your devDependencies.