Search code examples
node.jsamazon-web-servicesamazon-kinesisamazon-kcl

What is the proper 'require' for KCL in a NodeJS consumer application?


I'm reading through the docs for KCL (AWS's Kinesis Client Library) and if I'm understanding it correctly, I need to install the KCL itself (Java) and then my NodeJS consumer application will be able to access it. First of all, is this correct?

If so, I'm confused by the linkage between NodeJS and KCL. I see in the AWS sample code the line:

var kcl = require('../../..');

(found in sample here)

In NodeJS, I'm used to seeing JS files referenced in this way, not directories. This appears to be just traversing the file system 3 levels up and stopping. What is this a reference to? Is this the connection to KCL? Do I just need to ensure that my KCL installation is located at a relative path that will accommodate this require statement?


Solution

  • I need to install the KCL itself (Java) and then my NodeJS consumer application will be able to access it. First of all, is this correct?

    Yes, that's correct.
    If you install the KCL for nodejs and write your consumer app entirely in nodejs, you still need Java installed on your system because of the MultiLangDaemon. See the docs here.

    I'm confused by the linkage between NodeJS and KCL.

    When require is given the path of a folder, it'll look for an index.js in it. If there is one, it will use that, if there isn't, it will fail.

    In your example the kcl variable requires the index.js at the root directory.

    Do I just need to ensure that my KCL installation is located at a relative path that will accommodate this require statement?

    No, in a real world application you would require this module regularly like so var kcl = require('aws-kcl'), which is the name given to it in the package.json