FairCom has provided a tutorial to assist you in getting started with Node.js and the NAV API. This tutorial is located in the drivers\nodejs.nav\tutorials directory.
Prerequisites
Make sure you have Node.js and npm and Python installed on your computer, and all are executable from your command line. Python is used for building ffi-napi. To verify this, type the following commands into a command prompt:
node -v
npm -v
python -V
Node.js and npm are installed from the same package, which is available from https://nodejs.org. Node.js version 10 or later is required.
Python can be downloaded from https://www.python.org.
You will likely need to install windows-build-tools to complete your node development environment.
npm install --global --production windows-build-tools
The first time you use this tutorial, npm will probably try to build the ffi-napi module. For this to work properly, your computer should have a compiler installed on it. On Windows this is usually the Visual C++ Build Tools. Note that the Windows version of the Node.js installer might have already installed these tools for you.
Building the Tutorial
Open table...
Delete records...
Add records...
1000, Bryan Williams
1001, Michael Jordan
1002, Joshua Brown
1003, Keyon Dooling
Logout...
Troubleshooting
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
...etc…
The above error can happen on the “first run” if your install of Node.js / npm did not work correctly. Npm is trying to use Python to build the ffi-napi module and it is not working. Verify that Python is installed correctly and in the path.
error in tcp bind 10060
ctsqlConnectError: ctsql failed to connect with error -20212
The most common cause of this run-time error is the FairCom Database Engine is not running on your machine. The most likely cause is that the c-tree evaluation license times out after 3 hours and shuts down the server. The solution is to restart the server. See Starting the FairCom Database Engine.
could not logon: 133
This error is also caused by the FairCom Database Engine not running on your machine.
could not logon: 978
This error happens when the c-tree Server and this tutorial are running on the same computer, but they were started by different users. For example, one of the processes (the server or the tutorial) was run “as administrator”, but the other one was not. The shared memory segment (which is created by the c-tree server) is owned by the user who created it (the user who launched the c-tree server). A different user is not allowed to access that segment in Windows.
throw new Error('No native build was found for ' + target)
This runtime error indicates that foreign function interface (ffi-napi) module was not compiled properly. To resolve this remove the node_modules/ directory from drivers/nodejs.nav/ and from drivers/nodejs.nav/tutorials/cmdline/ and then rebuild the project.
Note that this tutorial depends on the foreign function interface (ffi-napi) module, which is a more modern / more maintained version of FFI. This module needs a compilation step the first time it is installed. (Note that ffi-napi comes with pre-built binaries, which might or might not work on your machine.) For the build to function properly, you will need a compiler installed on your system, as discussed in the "Prerequisites" section above.
could not connect: 101
If you get this error message, make sure the "ctreeSQL" database you are using actually exists.
Note: If you are using a self-signed certificate, Node-RED may reject the connection because it is considered unauthorized and Node-RED will show a SELF_SIGNED_CERT_IN_CHAIN error on the console. To work around this, set the NODE_TLS_REJECT_UNAUTHORIZED environment variable to 0, and restart Node-RED.
Example for Unix:
$ export NODE_TLS_REJECT_UNAUTHORIZED=0
$ node red.js -v push2omnibus.json