How to authenticate using Javascript SDK?

Nakama server is running fine. Then I just created a add_user.js file and using npm and “npm i @heroiclabs/nakama-js” ran this command. No error and I can see heroiclabs folder in node_modules folder. Then I wrote the following code
`
import {Client} from “@heroiclabs/nakama-js”;

var useSSL = false; // Enable if server is run with an SSL certificate.
var client = new Client(“defaultkey”, “127.0.0.1”, “7350”, useSSL);
`

and getting the error “SyntaxError: Cannot use import statement outside a module”. Can anyone please help? How to run the JS codes in the right way actually?

In your package.json, add:

{ "type": "module" }

I didn’t create any package.json file. I just created one js file and wrote the codes there. Can you please help?

Try replacing import with require?

Now,
`
const { Client } = require(“@heroiclabs/nakama-js”);

var useSSL = false; // Enable if server is run with an SSL certificate.

var client = new Client(“defaultkey”, “127.0.0.1”, “7350”, useSSL);

I am not getting any error with the above code. But If I add the below code with the above one
var email = “super@heroes.com”;

var password = “batsignal”;

const session = client.authenticateEmail(email, password);
`
I am getting ReferenceError: XMLHttpRequest is not defined

What about something like:

const nakama = require("@heroiclabs/nakama-js");
const client = new nakama.Client(“defaultkey”, “127.0.0.1”, “7350”, false);

getting same error!