Problem creating a class instance from node-js module

Viewed 111

I'm trying to use hitbtc-api node-module. Howerver, I'm not quite able to create the class instance correctly through its constructor. The example on its site says I should do it like this:

const restClient = new HitBTC({ key, secret, isDemo: false });

But I don't really know how to pass the key and secret there. I have tried this:

const restClient = new HitBTC({ "123456123456123456", "123456123456123456", isDemo: false });

In this case it returns error saying HitBTC is not a constructor.

I got that the constructor requires object as an parameter, but after this:

const restClient = new HitBTC({ key: "123456123456123456", secret : "123456123456123456", isDemo: false });

and still getting the same error, I gave up trying. Has anyone met with this instance creation before?

I'm a bit curious, because I have never seen an object without key names.

2 Answers

The "object without key names" thing is an ES2015 enhancement to the language, and it's super simple.

Essentially instead of:

const foo = 5;
const myObject = { foo: foo };

You can now say:

const foo = 5;
const myObject = { foo };

That's it :) When there's no key/value pair, it's assumed that the key name is the variable's name, and its value is the variable's value ... but everything still plays by all the rules of Javascript that you already know.

Understanding that, your final attempt to instantiate your HitBTC object looks correct ... so perhaps there's something wrong with the values of key or secret that you are using?

It's Not an issue with how you're calling but it's what you're calling, if you log the namespace associated with the package, it is an object with a method called default which is supposedly the class/constructor you're looking for. I'm not sure if this is intended though, you can look at the same here

Related