Product Documentation

c-treeDB API for Node.js

Previous Topic

Next Topic

Building and Running the Node.js NAV Tutorial - Linux

FairCom has provided a tutorial to assist you in getting started with NodeJS 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 executable from your command line. Python is used for building ffi-napi. To verify this, type the following commands into a shell:

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.

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 Linux, this is usually g++.

Building the Tutorial

  1. Be sure your c-tree server is running. See Starting the FairCom Database Engine.
  2. If this is the first time you have built this tutorial on this machine, be sure you have an active Internet connection, because npm will attempt to download several packages.
  3. In a command shell, change to the drivers/nodejs.nav/tutorials/cmdline directory.
  4. Execute the following command:

    make build

    This will cause npm to download needed packages, perhaps compile some .C and .CC files, and then copy some files.

  5. Then execute the following command to launch the tutorial:

    make run

    The tutorial should run and display the following:

node ctdb_tutorial1.js

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.

Error: ENOENT: no such file or directory, open 'libncurses.so.5'

This error arises in Linux if libncurses.so.5 is not installed. Many distributions have updated to libncurses.so.6, and may not have version 5 installed. To resolve this, follow the procedure for installing the version 5 Ncurses library that is appropriate for your architecture.

npm WARN

When “make build” is run by you or by a build script, you may see a warning similar to

npm WARN test@1.0.0 No description

npm WARN test@1.0.0 No repository field.

Those can be safely ignored.

Error: ENOENT: no such file or directory, open 'libmtclient.so'

If you get this message, make sure that you have properly set the LD_LIBRARY_PATH variable.

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

TOCIndex