2

I am trying to use the database methods like db._databases() or db._name() in a node app.

The manual shows require("@arangodb").db._name(); which works fine from arangosh but when I try to require('@arangodb') in the app, node throws

Error: Cannot find module '@arangodb'.

Attempting to install from NPM results in an error that it is not in the NPM registry.

So how can one require that namespace? Any pointers in the right direction would be greatly appreciated.

PS: I'm running the current 3.4rc in a docker container in case this makes a difference.

1 Answer 1

1

The @arangodb module can not be required in Node.js. It works in ArangoDB's V8 environment only. It is available in arangosh, Foxx, JS transactions and user-defined AQL functions.

If you want to talk to ArangoDB from a JavaScript environment like Node.js or a browser, then use the official JavaScript driver arangojs. Note that its interface is different from the one provided by the @arangodb module.

Sign up to request clarification or add additional context in comments.

4 Comments

I was modifying the example from the Node tutorial from the arango website which does a "db = require('arangojs')(); to include the official JS driver and succeeds in calling db.createDatabase('newDB') and db.useDatabase('newDB'). Calling db._name() afterwards results in "TypeError: db._name is not a function" even switching back to the systemDB with db.useDatabase('_system');. I tracked this down to what I thought was the @arangodb namespace missing but being new to the whole Node environment I may very well be wrong. How can you get a list of databases or the name of the current DB in node?
With db.get() and db.listDatabases(), see here: docs.arangodb.com/3.4/Drivers/JS/Reference/Database/…
Actually (await db.get()).name if you only want the name of the database (there are also the id, path and isSystem attribute). db.listDatabases() returns an array of strings with the database names. If you want to try this in Node interactively, you may need to do: var db = require('arangojs')(); (async function() { console.dir( await db.get() ) })()
You are welcome. If this solves your problem, please accept and up-vote the answer. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.