
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
basex-standalone
Advanced tools

Process data using XQuery with BaseX in standalone mode.
Install the module with: npm install basex-standalone
var basex = require('basex-standalone');
// prints '1 2 3 4 5 6 7 8 9 10'
basex({xquery: '1 to 10'}, function(error, data){
if(e) throw e
else console.log(data)
})
Or create a partial to set individual defaults
var basex = require('basex-standalone');
var b = basex.partial({
debug: true,
basexpath: '/tmp/basex'
})
// prints '/tmp/basex/data'
b({
serializer: { method: 'text' },
xquery: 'db:system()/mainoptions/dbpath/text()'
}, function(error, data){
if(e) throw e
else console.log(data)
})
BaseX includes a fast, feature-rich XQuery processor
that can juggle json, xml, csv and other data easily
and provides powerful document manipulation facilities
by implementing the XQuery Update specification.
For more information about BaseX,
what you can do with it,
and how to do it,
read through the excellent documentation on docs.basex.org
This module acts as a simple wrapper around BaseX's
Standalone Mode passing arguments via cli and reading back
stdout/stderr output.
Tip: For better performance, prefer Command Scripts over sequential invocations (ie multiple
ADD,SETcommands)
Use buffered output by passing a callback
var basex = require('basex')
basex({xquery: '1 to 10', function(error, data){
if(e) throw e
else console.log(data)
})
or directly access the ChildProcess:
var basex = require('basex')
var custom = basex.partial({classpath: 'path/to/basex.jar'})
var cp = custom({xquery: '1 to 10'})
cp.stdout.pipe(process.stdout)
Partials are a convenience to facilitate with default options handling.
var basex = require('basex-standalone')
var partial = basex.partial({debug: true, newlines: true})
partial('1 to 10')
partial('test.xql')
basex.partial(defaults)Returns: Function
Returns a partially applied function that will always use the provided options as defaults.
partial(options, callback)Returns: ChildProcess
Calling the partial will execute an operation.
Options are converted to BaseX standalone arguments.
For better understanding of these arguments see Startup Options.
Options object is also passed on to child_process.spawn() more
runType: String
Default value: ''
The actual operation to run.
Similar to RUN command. docs
Note:
runargument will directly evaluate as XQuery by BaseX if it doesn't point to a file. It is preferable to use theoption.xqueryin order to evaluate XQuery code.
commandsType: String|Array
Default value: []
Argument(s): -c<COMMAND>
Execute commands before running the operation.
bindType: Object
Default value: {}
Argument(s): -b<name>=<val>
Binds external variables to XQuery expressions. docs
xqueryType: String
Default value: null
Argument: -q<xquery>
Executes the specified string as XQuery expression before running the operation
and after executing the options.commands.
debugType: Boolean
Default value: false
Argument: -d
Toggles the debugging mode.
inputType: String
Default value: null
Argument: -i<input>
Sets file/directory to use as context.
outputType: String
Default value: null
Argument: -o<output>
Sets file to write all output to.
newlineType: Boolean
Default value: false
Argument: -L
Separates returned query items by newlines (instead of spaces) and appends a newline to the end of a result.
serializerType: Object
Default value: {}
Argument(s): -s<name>=<value>
Specifies parameters for serializing XQuery results. docs
updateType: Boolean
Default value: false
Argument: -u
Write updates back to original files.
whitespaceType: Boolean
Default value: false
Argument: -w
Preserve whitespaces from input files (-w).
javaType: String
Default value: /usr/bin/env java
Java executable to use.
classpathType: String|Array
Default value: null
CLASSPATH definition to be used by Java more.
In order for the module to work java needs access to org.basex.BaseX class.
Download the latest version from here
Alternatively org.basex.BaseX class must be available to java system-wide
(i.e. by setting the CLASSPATH environment variable).
Other useful files to include to the classpath are:
basexpathType: String
Default value: null
Path for BaseX Home Directory
Note that all file paths in commands / script etc remain relative to node's cwd
Modify a document in-place using xquery
basex({
input: 'path/to/some/file.xml',
update: true,
xquery: 'for $a in //a return replace value of node $a/@href with "#test"'
})
.then(function(data){
// Updating xquery expressions have no output
})
Execute an XQuery script file to query a folder with multiple xml files
basex({
input: 'path/to/some/dir',
run: 'path/to/some/script.xql'
})
.then(function(output){
console.log(output)
})
Execute a BaseX Command Script to batch-process json and xml data
<!-- some/command/script.bxs -->
<commands>
<info/>
<create-db name="test"/>
<add path="test.xml">some/file.xml</add>
<set option="parser">json</set>
<set option="createfilter">*.json</set>
<add>somedir/with/json/files</add>
<xquery>
<![CDATA[
for $book in //json/book
let $author = $book//author
group by $author/@id
return
<author books="{{count($book)}}">{{$author/text()}}</author>"
]]>
</xquery>
<drop-db name="test"/>
<commands>
basex('some/command/script.bxs', function(error, data)
if(e) throw e
else console.log(data)
})
1.4.0 - basex.Job moved to it's own module
1.3.0 - Lets the user handle the classpath
1.2.0 - Simplify API and drop Q dependency
1.1.0 - Include jar via downloading upon installation
1.0.2 - fix order of required modules
1.0.1 - fix multiple values for options.classpath
1.0.0 - First Official Release
Copyright (c) 2013 Alexandros Sigalas Licensed under the MIT license.
FAQs
Process data using XQuery with BaseX in standalone mode.
We found that basex-standalone demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.