Node.js Client API

Node.js

What It Is

The MarkLogic Node.js Client API is an open-source JavaScript library that allows developers to quickly, easily, and reliably access MarkLogic from applications built using Node.js—the most popular web server for easily building fast, scalable network applications using non-blocking, asynchronous I/O.

Access the Node.js Client API Git Repo


Async I/O

Why It Matters

For developers using—or looking to use—Node.js in their application stacks, the Node.js Client API is the fastest, easiest, and most reliable way to communicate with a MarkLogic database.

The API provides an asynchronous JavaScript interface for key MarkLogic capabilities, such as search, document management, batch loading, transactions, aggregates, and alerting. Combined with MarkLogic’s ability to index and manage JSON documents natively, the Node.js Client API is an ideal tool for full-stack JavaScript development.

The Node.js Client API is written in JavaScript specifically for Node, and encapsulates best practices on both the Node and MarkLogic ends. For example, asynchronous I/O is enforced throughout, and conveniences are provided for building complex queries. Its interface is designed to be familiar and comfortable to Node developers. For performance-critical or resource-intensive operations, the Node.js Client API provides an extension mechanism that executes JavaScript on server, where it runs close to the data.

The Node client is developed in the open on GitHub and is licensed under the open-source Apache 2.0 license. The best way to get involved is to log issues for bugs or new features.

Here’s a quick example to demonstrate how a Node application would build a query and process the results.

var marklogic = require('marklogic');
var conn = require('./env.js').connection; // Host and auth details

var db = marklogic.createDatabaseClient(conn);
var q = marklogic.queryBuilder;
db.documents.query(
  q.where(
    q.collection('countries'),
    q.value('region', 'Africa'),
    q.or(
      q.word('background',   'France'),
      q.word('Legal system', 'French')
    )
  )
)
  .result(function(documents) {
    documents.forEach(function(document) {
      console.log(JSON.stringify(document))
    })
  });