MarkLogic integrates JavaScript as a first-class server-side programming language. You can call a JavaScript program from an App Server, and that program has server-side access to the MarkLogic built-in functions. When you put a JavaScript module under an App Server root with a `sjs` file extension, you can evaluate that module via HTTP from the App Server.

Server-Side JavaScript in MarkLogic

MarkLogic integrates JavaScript as a first-class server-side programming language. You can call a JavaScript program from an App Server, and that program has server-side access to the MarkLogic built-in functions.

MarkLogic Server integrates the Google V8 JavaScript engine ( https://code.google.com/p/v8/), a high-performance open source C++ implementation of JavaScript.

This version of V8 offers some of the newer EcmaScript 2015 (formerly known as EcmaScript 6) features. Some EcmaScript 15 features are:

  • Arrow Function
  • Spread Operator and rest Parameters
  • Maps and Sets
  • Classes
  • Constants and Block-Scoped Variables
  • Template Strings
  • Symbols

Programming in Server-Side JavaScript

When you put a JavaScript module under an App Server root with a sjs file extension, you can evaluate that module via HTTP from the App Server. For example, if you have an HTTP App Server with a root /space/appserver, and the port set to 1234, then you can save the following file as /space/appserver/my-js.sjs:

xdmp.setResponseContentType("text/plain");
"hello"

Evaluating this module in a browser pointed to http://localhost:1234/my-js.sjs (or substituting your hostname for localhost if your browser is on a different machine) returns the string hello.

Reference