Question
· Aug 2, 2016

how to connect to the Cache database from node.js ?

I cannot connect to Cache from node.js  

I have installed in Windows 10 the following: CACHE 2016, node.js v 4.4.7 and  express .

-  where can I get cache.node? The link in the Intersystmes documentation  http://globalsdb.org/downloads/  doesn't work. I found cache0100.node and cache0120.node  in my Cache instance's  \bin directory. But I am not sure if I can use them or not.

 - how to install cache.node ? Where do I place it exactly? 

Can anyone recommend any tutorial or code example with installation instructions?

Thank you!

Discussion (12)3
Log in or sign up to continue

-  where can I get cache.node? The link in the Intersystmes documentation  http://globalsdb.org/downloads/  doesn't work. I found cache0100.node and cache0120.node  in my Cache instance's  \bin directory. But I am not sure if I can use them or not.

Cache instance's  \bin directory is the correct path.

Can anyone recommend any tutorial or code example with installation instructions?

Samples are provided in <CacheDir>\dev\node.js\samples directory. Installation instructions are located in settings.js file.

Hi Eduard!

Thank you  for  your response. 

I still cannot make it work and have questions:

1) I am not sure which file to use as cache.node. The setting.js doesn't list my version of node.js  ( which is V4.4.7 ):

//               v0.8.x  (x >= 2)    cache082.node
//               v0.10.x (x >= 0)    cache0100.node
//               v0.12.x (x >= 0)    cache0120.node   ({Caché | Ensemble} version 2015.2 and above)
Should I use "cache0120.node" in my case ? if not then where can I download cache.node for nodejs v4.4.7 ?

 

2) When I assume that cache0120.node is the right DLL file,  rename  it to "cache.node",  place it in Cache instance's  \bin directory and  use the following settings in settings_local.js:

         return {use: 1, ins_dir: 'C:/InterSystems/TryCache/', cn_dir: '', name: 'TryCache'};

I am getting the error:

C:\InterSystems\TryCache\dev\node.js\samples>node dir_sync.js
module.js:434
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: The specified procedure could not be found.
\\?\C:\InterSystems\TryCache\bin\cache.node
    at Error (native)
    at Object.Module._extensions..node (module.js:434:18)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\InterSystems\TryCache\dev\node.js\samples\dir_sync.js:66:15)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)

which makes we think that "ins_dir" is not set correctly.  The instruction in settings.js does not provide an example for Windows. Can you give me an example how to specify the path in case of Windows? 

Thank you!

With Node.js versions coming in thick and fast, the question: "where do I get the appropriate version of cache.node?" is increasingly a problem for people who want to use Cache with Node.js.  

Bundling the latest versions of cache.node with build kits for the latest versions of Cache makes little sense - people need to use Node.js with whatever version of Cache they currently have installed and use.  If they update Node.js (which, as I say, is a frequent requirement these days), they won't want or expect to update Cache too.  So currently you have to download a Cache kit and install it on some temporary machine just to extract the latest cache.node files.

Instead, can I request that the cache.node kits are distributed separately in a location that users can know to look for?

Anyone else agree?

Rob

Hi Stephan, that's really great news! Is there any progress on the npm release of the Node.js connector?

Currently I need to use the field test connector version in my production environment (!) because I need the Node.js 4.x version - many npm modules already require a much more recent Node.js version 4 to install. In the latest official 2016.1 release there is only a v0.10 and a v0.12 connector available.

Thanks in advance!

If your Node.js version is 4.4.7, you need the Node.js connector provided in the latest field test. If you have a WRC login, you can find it under "developer download". Be aware this is a field test version - not ready for production use.

The existing versions you'll find in the latest official release (2016.1) are cache0100.node (for Node.js version 0.10.x) and cache0120.node (for version 0.12.x). If you install a on a 64-bit Windows, you also need to install the Node.js 64-bit binary and use the corresponding 64-bit cache.node connector you'll find in the Caché bin directory - as Caché follows the OS architecture version, everything needs to be of the same architecture version - Node.js itself and also the cache.node connector. Just put the connector in your node_modules directory (where you install your other Node.js modules using npm) and rename it to cache.node, that's all! You then just put require('cache') in your Javascript code and you can open a Caché connection.

If you need the cache.node connector for the current Node.js LTS version 4.x from the field test, you don't need to install the Caché field test completely - you can also extract it from the field test installation package (cache-2016.3.0.640.0-win_x64.exe) using e.g. 7-Zip: first extract the field test installer exe to a temp dir and next, also extract the other_~1.cab file in the temp dir to another temp dir. You'll find there a cache421.node connector you can use with Node.js version 4.x (currently v4.5.0).

One more tip: to determine if a certain cacheXXXX.node connector version will work with your Node.js version, you can check the Node.js release table: you need to look at the NODE_MODULE_VERSION column. As long as the module version number is the same, it will work with that Node.js version. E.g. in the field test installer, you'll find a cache421.node connector for version 4.2.1. As this is module version 46, it will also work on Node.js 4.4.7 and 4.5.0. But it will not work on version 6.x (module version 48 is required for that).

And in addition, always remember the OS architecture (x86 or x64) needs to be the same for Caché, Node.js and the cache.node connector! wink

HTH,
Ward

does cache have to be the unicode version or can we use nodeJS with "standard cache" (I'm using nodejS 4.2.1 in a windows environment with 2016.1 cache)

the reason I ask, I have installed the nodeJS (64bit) and it's fully working with the unicode version of cache (I read that I should be using unicode somewhere) but when I try to copy the same setup into 32bit windows environment (NON unicode) making sure I have the 32bit nodeJS, it won't connect,

Been through loads of things, but its only unicode/non-unicode that seems to be different

In answer to your question: 

"Can anyone recommend any tutorial or code example with installation instructions?"

I'd recommend reading through the comprehensive training course on EWD 3 at http://www.mgateway.com - click the Training tab there for details

The EWD 3 module called ewd-xpress provides a ready-to-run and easy-to-use Node.js-based platform for your Cache applications.  It uses cache.node to provide the connection to Cache and abstracts its APIs to make Cache behave as persistent JavaScript objects and a fine-grained Document Database. The online course will explain all!