Search code examples
fusionauth

Getting FusionAuthClient is not a constructor error


I am trying the fusionauth-node-client and following the wiki https://fusionauth.io/docs/v1/tech/client-libraries/node. But I am getting the following error

const client = new FusionAuthClient('6b87a398-39f2-4692-927b-13188a81a9a3', 'http://localhost:9011');
               ^

TypeError: FusionAuthClient is not a constructor
at Object.<anonymous> 

I have pasted the exact code mentioned in the doc still it is not working. Can anyone help me in identifying what I am missing here.


Solution

  • I dug around in the library and noticed that we are exporting several objects and our example is no longer correct.

    To get the client you need to change your syntax a little bit to get the correct object.

    const {FusionAuthClient} = require('fusionauth-node-client');
    

    This translates to: require the library fusionauth-node-client and give me the FusionAuthClient from inside it. There are also a RESTClient and JWTManager available in the library but you shouldn't need either of those to code with FusionAuth.

    I will also update our example to correct this discrepancy.