Installing NPM Libraries
  • 20 Mar 2024
  • 7 Minutes to read
  • PDF

Installing NPM Libraries

  • PDF

Article summary

Scripting supports the use of any third-party libraries with the following limitations:

  • The library must be compatible with node 12.22.12
  • Native libraries can or can not work depending on how they interact with the Node.js runtime. In general, N-API libraries and NAN libraries that are declared as "context aware" should work, but it depends on the implementation of each library.

 Node.js version 12.22.12 must first be installed on the host machine in order to install a new third-party library and all of its dependencies from the NPM using just one single command. The following sections show how to install Node.js 12.22.12, as well as how to install NPM libraries.

Installing Node.js 12.22.12

  • Download the installer from https://nodejs.org/dist/v12.22.12/. There are two versions for Windows, one for 32-bit (node-v12.22.12-x86.msi), and one for 64-bit OS, located in the x64 folder(node-v12.22.12-x64.msi), the recommended one is the 64-bit version.
  • Execute the installer by double clicking on it.


Click next until the Custom Setup window is opened. Include NPM package manager in the features to install. It is also advisable to add Node.js to PATH: 


Keep clicking next until Node.js finishes installation. It will then be possible to test if that node has been successfully installed by opening a command prompt, and running the following command to get the Node.js version installed: node --version.



Installing NPM libraries

In this example, the got library will be installed in the N3uron node.

  1. The first step is to search for the NPM got library, which in this case is located at https://www.npmjs.com/package/got. Since the library must be compatible with Node 12.22.12, the package.json file of the library must be checked to see if it lists the minimum compatible version of Node.js. This file can be found by navigating to the repository of the library:
                                                                                                                                                                                                                                                                                                                                                               
  2. In the repository, the package.json file can be checked to see if it lists the minimum supported Node.js version. This property is not mandatory, so some libraries might not have it, but since it's good practice to include it, most will have it.
                                                                                                                                                                                                                                                                                                                                                                             
  3. Within this package.json file, the keyword “engines” can be found using the search function. This keyword is used to indicate the minimum node version supported by the library, if present. If not, the only way to test whether the library is compatible with Node.js 12.22.12 is by trial and error, i.e. by installing the library and trying to use it. The following screenshot shows that the current version of the library requires a Node.js version higher than 14.16, and therefore, this library is not compatible with N3uron.               
                                                                                                                                                                                                                                                                                                                                                            
  4. Even though the current version is not compatible, an older version might be. Older versions can be checked by checking the tags in the reposotiry, until one of the older version is compatible with N3uron
                                                                                                                                                                                                                                                                                                                                                                
  5. Checking the package.json of the 11.8.3 version shows that this version is compatible with N3uron:                             
                                                                                                                                                                                                                                                                                                                                  
  6. In order to install the library, a command prompt in the destination folder (usually N3uron/data/Scripting) must be opened. Once it's open, the following command installs the specific library and version:
    Shell
    Shell
    Shell
    Shell
    npm install LIBRARY_NAME@LIBRARY_VERSION
    In this example, the following command must be used:

    Shell
    Shell
    Shell
    Shell
    npm install got@11.8.3
     

 After executing this command, the got library will be install to the node_modules folder (which is created if it doesn't exist) in the Scripting data folder. In order to load the library, a new external library must be created (more information at Libraries), and it's path has to point to node_modules/got.



Was this article helpful?

What's Next