node.jsarangodbarangojs

arangoDb + nodejs: db.useBasicAuth(...) is not a function


So, I have code bellow:

const { Database, aql }  = require("arangojs");

const db = new Database({·
  url: 'http://127.0.0.1:8529'
} );
db.useBasicAuth('root', 'password1')
(async function() {
  const now = Date.now();
  try {
    const cursor = await db.query(aql`RETURN ${now}`);
    const result = await cursor.next();
  } catch (err) { console.log(err) }
})();

which gives me an error:

TypeError: db.useBasicAuth(...) is not a function

version of the driver is:

"arangojs": "^6.3.0"

Any ideas?


Solution

  • There is a missing semicolon after call to db.useBasicAuth. The immediate execution function on the next line confuses the "no semicolons anymore" syntax. Its trying to run the result of the useBasicAuth function with the function on the following line as the parameter, but useBasicAuth does not return a function.

    This will get rid of the type error:

    const { Database, aql }  = require("arangojs");
    
    const db = new Database({·
      url: 'http://127.0.0.1:8529'
    } );
    db.useBasicAuth('root', 'password1');
    (async function() {
      const now = Date.now();
      try {
        const cursor = await db.query(aql`RETURN ${now}`);
        const result = await cursor.next();
      } catch (err) { console.log(err) }
    })();