Make sure you have Node.js and npm are installed and executable from your command line.
Node.js changes slightly from version to version. We expect these directions to be similar for most versions, however if you have difficulty, please contact FairCom.
npm init --yes
This will create a new package.json file with default values.
npm --save install path_to_your_ctsql
Replace path_to_your_ctsql with the actual path to the FairCom SQL module for Node.js. This path is typically drivers\<Your-API-Folder> within a FairCom package.
This will create a node_modules folder containing the FairCom SQL module (a symbolic link to the actual modules) and it changes package.json, adding a dependency to the module.
Note: It may be necessary to update to the latest version of npm. (For example, many Raspberry Pi Raspbian devices come pre-installed with an old version.) npm is easily updated as followed:
> sudo npm install -g npm@latest
Because of the dependency on FairCom DB SQL libctsqlapi.so or ctsqlapi.dll, on some platforms you will need to ensure those libraries are in your directory or path for proper loading. On Linux, use LD_LIBRARY_PATH to set your location of this shared library. Using bash, for example, the following assumes the library is in your current running location:
export LD_LIBRARY_PATH=<path-to-the-client-side-library>
Certain Linux platforms may also require exporting LD_PRELOAD to properly enable TLS (SSL) support. If you find a dlload error on execution this may be a reason. Locate your current openssl library and export this environment variable similar to the following example:
export LD_PRELOAD=/usr/lib64/libssl.so.1.0.2k
Both of these exports can also be included in a script used to execute your Node.js application.
Note: On a newly installed Windows 10 machine, you may need to install windows-build-tools:
npm install --global --production windows-build-tools
The following commands should not be needed because this should be done transparently as a dependency of the module. If necessary, you may wish to install other Node.js packages, such as ffi-napi and ref:
npm install ffi-napi
npm install ref
Note: The FairCom driver for Node.js is designed for traditional, single-threaded Node.js applications. Each instance of Node.js should run one thread, but it can connect many times to the FairCom database for different purposes. Different instances of Node.js can safely connect to the same database and process data in parallel.