Node.js integrates with M: The NoSQL Hierarchical database

We have talked recently about the significance of integrating the Node.js language with the powerful M database, particularly in the space of healthcare applications.


The efficiency of Node.js combined with the high performance of M, provides an unparalleled fresh approach for building healthcare applications.

Here is how you can try this today:

  • Install GT.M (the open source implementation of M)
  • Install Node.js
  • Install the nodem module that provides Node.js drivers for M
  • Install the ewdglobals module that provides Node.js integration

With this, you are now ready to try the following examplesLet’s start with an easy one:


var db = new nodem.Gtm();


var patient = new ewd.GlobalNode(‘patient’,[123456]);

var document = {
  “name”: “John Doe”,
  “city”: “New York”



If we put this in a file called exampleA.js and run it with:

We can then inspect the state of the entry in the M database with the ZWRITE command:

To find that it is now set to:

This reflects the mapping between the tree-like hierarchical structure of M multi-dimensional arrays, and the nested properties structure of Node.js objects.

We can also use Node.js to get an entire entry from the M database into a JSON structure, and then print it to the console by using the following two lines:

By using jQuery inspired notation, we can now access further elements down the hierarchical structure of the M entry:

console.log(‘Name: ‘ + nameValue + ‘ City: ‘ + cityValue);

A more complete example illustrates the use of multiple levels of the data hierarchy:

var db = new nodem.Gtm();


console.log(“Setting a Global”);;


var document = {
  “name”: “John Doe”,
  “city”: “New York”,
  “treatments” : {
    “surgeries” : [ “apendicectomy”, “biopsy” ],
    “radiation” : [ “gamma”, “x-rays” ],
    “physiotherapy” : [ “knee”, “shoulder” ]


console.log(“Querying properties”);

// By quering for a subscript, all its attributes
// become available as properties.
var treatementsObject = patient.$(‘treatments’);

console.log(‘Surgeries: ‘);
patient.treatments.surgeries._forEach( function( id, subNode ) {
  console.log( ‘id: ‘ + id + ‘:’ + subNode._value );

// Accessing radiation treatements
console.log( patient.treatments.radiation[0]._value );
console.log( patient.treatments.radiation[1]._value );


Note in particular, the use of the forEach() construct to visit all the elements of an array in the structure. And the use of the dot notation for progressively accessing each one of the properties that map to M sub-indices.

This is a similar to the MongoDB storage based on JSON structures, but with the difference that we can access the internal elements of the data structure.

This modern integration of Node.js with M offers a unique opportunity for Javascript developers to enter the field of healthcare IT applications and bring rapid innovation to it.

Node.js developers: Healthcare needs your help!

Questions or comments are always welcome!