Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
zadravecm
New Contributor III

npm node library in Qlik sense visual extension

Hi,

I would like to include Request library in my extension.

I know that Qlik Sense use RequireJS for bringing resources in extension.

So I did something like this:

define([

        "jquery",

        "request"

    ],

    function(jq, request) {

......

     });

But I get (in browser - developer tools) error :

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:4848/resources/request.js?.....

I did do:

npm install request

inside my_extension folder.

What I am doing wrong?

5 Replies
erik_wetterberg
Honored Contributor

Re: npm node library in Qlik sense visual extension

Hi,

If you load additional libraries in your extensions you need to use a relative path. So if you want to load library xxxx.js you put it in folder xxxx under your main extension folder and then load it with:

define(['./xxxx/xxxx'],function(xxxx){ //note the dot!!

........

}

Assuming that the library can be loaded with requirejs.

Hope this helps

Erik Wetterberg

Erik Wetterberg
https://extendingqlik.upper88.com/
zadravecm
New Contributor III

Re: npm node library in Qlik sense visual extension

Thank you for reply. I see that you could specify the external js file with relative path.

My problem however is that I would like to include whole model (a lot of js files) to this extension.

The problem is, that I could include main js file (in my case request.js) , but all other dependencies inside this modul (request.js file) will not be resolved.

I also have a problem, that if I try to do:

define([

        "jquery",

        "./node_modules/request"

    ],

    function(jq, request) {

......

               var req = { method: 'GET', url: '/hello', baseUrl: baseUrl };

                request(req, this.log);

....

});

it seas :

request is not a function. (Witch I understand, that define function return object. But I need to call init function in this case).

Do you have any experience with this?

erik_wetterberg
Honored Contributor

Re: npm node library in Qlik sense visual extension

Hi,

This looks like somthing meant for nodejs rather than the browser. Why do you need it? Generally you should avoid loading a lot of files in an extension, if possible use a packaged solution.

Erik Wetterberg

Erik Wetterberg
https://extendingqlik.upper88.com/
zadravecm
New Contributor III

Re: npm node library in Qlik sense visual extension

Isn't RequireJS from NodeJS?


I can see that in the beginning the whole library jquery is loaded. I would like to do it similarly with other library.

I have for example CryptoJS, witch I can't found to be as a single JS file.


ajaykakkar93
Contributor

Re: npm node library in Qlik sense visual extension

Hi erik.wetterberg,

     i am trying to load mysql in to my extension itselfe so do you have a way to do that,

i am facing a similar issue as zadravecm

Regards & Thanks,
Ajay Kakkar
ajaykakkar93@gmail.com
Community Browser