
Security News
AI Has Taken Over Open Source
Vibe coding at scale is reshaping how packages are created, contributed, and selected across the software supply chain
@existdb/node-exist
Advanced tools
Mostly a shallow wrapper for eXist's XML-RPC API. Attempts to translate terminologies into node world. Uses promises.
npm install @existdb/node-exist
Creating, reading and removing a collection:
const exist = require('@existdb/node-exist')
const db = exist.connect()
db.collections.create('/db/apps/test')
.then(result => db.collections.describe('/db/apps/test'))
.then(result => console.log('collection description:', result))
.catch(e => console.error('fail', e))
Uploading an XML file into the database
const exist = require('@existdb/node-exist')
const db = exist.connect()
db.documents.upload(Buffer.from('<root/>'))
.then(fileHandle => db.documents.parseLocal(fileHandle, '/db/apps/test/file.xml', {}))
.then(result => db.documents.read('/db/apps/test/file.xml'))
.then(result => console.log('test file contents', result))
.catch(error => console.error('fail', error))
Since all interactions with the database are promises you can also use async functions
const exist = require('@existdb/node-exist')
const db = exist.connect()
async function uploadAndParse (filePath, contents) {
const fileHandle = await db.documents.upload(contents)
await db.documents.parseLocal(fileHandle, filePath, {})
return filePath
}
// top-level await is not available everywhere, yet
uploadAndParse('/db/apps/test-file.xml', Buffer.from('<root/>'))
.then(filePath => console.log("uploaded", filePath))
.catch(error => console.error(error))
You can also have a look at the examples for more use-cases.
Connect as someone else than guest
exist.connect({
basic_auth: {
user: 'me',
pass: '1 troubadour artisanal #compost'
}
})
Connect to a local development server using HTTP
exist.connect({ secure: false, port: 8080 })
Connect to a server with an invalid or expired certificate
exist.connect({ rejectUnauthorized: false })
readOptionsFromEnv offers an comfortable way to read the connection options
from a set of environment variables
| variable name | default | description |
|---|---|---|
EXISTDB_USER | none | the user used to connect to the database and to execute queries with |
EXISTDB_PASS | none | the password to authenticate the user against the database |
EXISTDB_SERVER | https://localhost:8443 | the URL of the database instance to connect to (only http and https protocol allowed) |
const {connect, readOptionsFromEnv} = require('@existdb/node-exist')
const db = connect(readOptionsFromEnv())
For more details you can have a look how it is used in the connection script that is used for testing and in all example scripts and the examples.
{
host: 'localhost',
port: '8443',
path: '/exist/xmlrpc', // you most likely do not need to change that
basic_auth: {
user: 'guest',
pass: 'guest'
},
secure: true
}
The methods are grouped into components by what they operate on. Every method returns a promise.
Status: working
db.queries.execute(query, options)
db.queries.read(query, options)
This convenience function calls queries.count then retrieves all result pages and returns them in an array.
db.queries.readAll(query, options)
Example:
const query = `xquery version "3.1";
xmldb:get-child-collections($collection)
=> string-join(",\n")
`
const options = { variables: collection: "/db/apps" }
db.queries.readAll(query, options)
.then(result => {
const response = Buffer.concat(result.pages).toString()
console.log(response)
})
.catch(error => console.error(error))
db.queries.count(resultHandle)
db.queries.retrieveResult(resultHandle, page)
db.queries.retrieveAll(resultHandle)
free result on server
db.queries.releaseResult(resultHandle)
A document can be seen as a file. It might be indexed if it's type is not binary.
Resolves into a file handle which can then be used by db.documents.parseLocal.
db.documents.upload(Buffer.from('test'))
db.documents.parseLocal(fileHandle, 'foo/test.txt', {})
db.documents.read('foo.xml')
db.documents.remove('foo.xml')
Status: working
A resource is identified by its path in the database. Documents and collections are resources.
db.resources.describe(resourcePath)
db.resources.setPermissions(resourcePath, 400)
db.resources.getPermissions(resourcePath)
Status: working
db.collections.create(collectionPath)
db.collections.remove(collectionPath)
db.collections.describe(collectionPath)
db.collections.read(collectionPath)
Status: working
After uploading a XAR you can install it
db.app.upload(xarBuffer, xarName)
Example:
const xarContents = fs.readFileSync('spec/files/test-app.xar')
db.app.upload(xarContents, 'test-app.xar')
.then(result => console.log(result))
.catch(error => console.error(error))
Install an uploaded XAR (this will call repo:install-and-deploy-from-db).
For extra safety a previously installed version will be removed before
installing the new version.
Dependencies will be resolved from http://exist-db.org/exist/apps/public-repo
by default.
If you want to use a different repository provide the optional customPackageRepoUrl.
db.app.install(xarName[, customPackageRepoUrl])
Example:
db.app.install('test-app.xar')
.then(result => console.log(result))
.catch(error => console.error(error))
Returns
{
"success": true,
"result": {
"update": false, // true if a previous version was found
"target": "/db/apps/test-app"
}
}
Error
{
success: false,
error: Error
}
Uninstall and remove the application identified by its namespace URL.
If no app with packageUri could be found then this counts as success.
db.app.remove(packageUri)
Example:
db.app.remove('http://exist-db.org/apps/test-app')
.then(result => console.log(result))
.catch(error => console.error(error))
Returns
{ success: true }
Error
{
success: false,
error: Object | Error
}
Status: TODO
Status: failing
db.users.byName(username)
db.users.list()
Status: working
db.server.syncToDisk()
db.server.shutdown()
Note: There is no way to bring it up again.
You can use this library to interact with local or remote existdb instances on the command line. You can find a few basic examples in this repository.
To give you a taste all example scripts are exposed as binaries in the node_modules/.bin folder when you install this package.
You can run them using npx
npx -p @existdb/node-exist exist-ls /db/apps
If you want you can even install this package globally and then use these scripts like ls or cd.
npm install -g @existdb/node-exist
Now you can type
exist-ls /db/apps
anywhere on the system.
All tests are in spec/tests and written for tape
npm test
NOTE: You can override connection settings with environment variables. See examples for more information.
To execute a single run using a different server you can also just define the variable directly:
EXISTDB_SERVER=http://localhost:8888 npm test
node-exist is tested to be compatible with eXist-db 4 and 5. It should be compatible with version 3, except XAR installation.
Use at your own risk.
This software is safe for development. It may be used to work with a production instance, but think twice before your data is lost.
FAQs
promise based interaction with eXist DB's XML-RPC API
The npm package @existdb/node-exist receives a total of 125 weekly downloads. As such, @existdb/node-exist popularity was classified as not popular.
We found that @existdb/node-exist demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Vibe coding at scale is reshaping how packages are created, contributed, and selected across the software supply chain

Security News
npm invalidated all granular access tokens that bypass 2FA after a fresh Mini Shai-Hulud wave compromised 323 npm packages. Staged publishing also entered public preview.

Research
/Security News
Compromised npm package art-template delivered a Coruna-like iOS Safari exploit framework through a watering-hole attack.