0

I'm trying to do some exercises, like this one: https://blogs.sap.com/2016/03/28/developing-with-xs-advanced-add-business-logic-with-nodejs/

In that exercise, there is this code snippet:

function saveCountry(country){
   var conn = $.hdb.getConnetion();
   var output = ...
}

And no matter what, I got this error :

500 Cannot read property 'getConnection' of undefined

Additionally, I tried to make a Node.js from terminal, using vim, node and xs as in this documentation: https://help.sap.com/viewer/4505d0bdaf4948449b7f7379d24d0f0d/2.0.02/en-US/32392948cb1844b2a6ed22ad641d4461.html

In item 3 of that documentation there's this code snippet:

var express = require('express');
var app = express();

var xsenv = require('@sap/xsenv');
var services = xsenv.getServices({ hana:'myhana' });
// also tried this ways: 
//        xsenv.getServices({hana: {tag:'myhana'}});
//        xsenv.getServices({hana: {tag:'hana'}});

app.get('/', function (req, res) {
  res.send('Using HANA ' + services.hana.host + ':' + services.hana.port);
});

var port = process.env.PORT || 3000;
app.listen(port, function () {
  console.log('myapp listening on port ' + port);
});

Now, create a service:

xs create-service hana hdi-shared myhana

And also, verify that service exists:

xs s

Then, run the nodejs-app with :

xs push

And result error:

No service matches hana

So, in resume, what am I missing in order to use $.hdb.getConnetion(); ?

When I created the project from webIDE I clicked option enable xsjs, that's so, that I have this var xsjs = require('@sap/xsjs');

And, in the other exercise, how is that "no service matches" and I clearly see it!

This is the version installed and box specs:

HDB version info:
  version:             2.00.030.00.1522210459
  branch:              hanaws
  machine config:      linuxx86_64
  git hash:            bb2ff6b25b8eab5ab382c170a43dc95ae6ce298f
  git merge time:      2018-03-28 06:14:19
  weekstone:           2018.13.0
  cloud edition:       0000.00.00
  compile date:        2018-03-28 06:19:13
  compile host:        ld2221
  compile type:        rel

RedHat 7.5

Thanks a lot for all help.

xOCh

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
xOCh
  • 1
  • 2

1 Answers1

0

For the first snippet, I must warn that XSJS using express is not supported any more for the version you are using of HANA Express.

However, in both the first and the second error, you seem to be missing the dependency between the node module and the database module, or somehow the HDI container is not bound to your js app.

For example, the dependency can be set in the mta.yaml file if you are using Web IDE for HANA:

modules:
  - name: db
    type: hdb
    path: db
    requires:
      - name: hdi_db
  - name: js
    type: nodejs
    path: js
    provides:
      - name: js_api
        properties:
          url: '${default-url}'
    requires:
      - name: hdi_db
      - name: db 
resources:
  - name: hdi_db
    properties:
      hdi-container-name: '${service-name}'
    type: com.sap.xs.hdi-container

There is an example of this here: https://www.sap.com/developer/tutorials/xsa-xsjs-xsodata.html

If this is in place, you can check the binding with command xs s in the CLI (switch to the space you are using with xs target, e.g.: xs target -s development )

If you only see di-builder under bound apps for the database service and you do not see the js module, they are not bound. You can bind the js app to the db service with command xs bind-service, e.g.:

xs bs XSA_DEV-3blurblurb-test-js XSA_DEV-3bkurblurb-test-hdi_db
Lucia S
  • 438
  • 3
  • 7
  • Lucía, thanks for answer and sorry to response until now. Still not clear, XSJS using express is not supported, but that's apply to all versions or it's because it is hana express ? In the first link i posted, the talk about a procedure created in the tinydb that it's called from javascript using XSJS, if it's not longer supported, then how can i call that procedure ? Also, i have many issues trying to use https://npm.sap.com as a registry with node, got a fibrous error at make. Im in RHEL 7.5. – xOCh Jun 19 '18 at 01:33
  • That applies to your version HXE 2.0 SPS03, in the previous one, it was supported. Your error is not related to this anyways and you can call the procedure in xsjs without express involved. – Lucia S Jun 19 '18 at 23:37
  • I have remove "express" node module as a dependency in code, and im not able to use $.hdb.getConnection(); is that what you meant? – xOCh Jun 21 '18 at 05:35
  • No, did you check the rest of the answer? The problem is in the binding between the node module and the database module. – Lucia S Jun 21 '18 at 15:24