# Using Native NodeJS modules

To extend the power of vREST NG core engine, you may even require native npm packages as well in utility methods. For that you will need to setup the package.json file in the vREST NG project directory and install the dependencies. And you will also need to rebuild the native module(s)

  • against the specific ElectronJS version which is embedded in the vREST NG Application
  • against the specific NodeJS version which is embedded in the vREST NG CLI

# Steps

  1. First define a package.json file in your vREST NG project directory with all the dependencies (native or normal dependency) which you want to use in your API tests.
{
  "name": "tests-using-npm-packages",
  "description": "This explains, how you may use npm packages in your api tests.",
  "version": "1.0.0",
  "keywords": [
    "vrest-ng",
    "native-npm-modules"
  ],
  "dependencies": {
    "msnodesqlv8": "^2.0.5",
    "mssql": "^6.2.1"
  }
}

Suppose we would like to connect with mssql database in vREST NG. So, define the desired dependencies in the package.json file as shown above.

  1. Now install the dependencies by using the following command:

npm install

  1. Now, you will need to rebuild the native NodeJS modules for vREST NG Application and vREST NG CLI separately.

    1. To rebuild the native NodeJS module for vREST NG Applicaiton, simply use the NodeJS module electron-rebuild. This module will help you in rebuilding the native module against the specific ElectronJS version of the vREST NG Application using the command below:
    electron-rebuild -v ELECTRONJS_VERSION -b -f -w NATIVE_MODULE_NAME
    

    here ELECTRONJS_VERSION is the version of the ElectronJS framework which is used in the vREST NG Application. You may find this version information in our guide on Embedded Library Versions.

    You may add the above command in your package.json file as well in the scripts section as shown below:

    {
      "name": "tests-using-npm-packages",
      "description": "This vREST NG Project directory explains, how you may use npm packages in your api tests.",
      "version": "1.0.0",
      "keywords": [
        "vrest-ng",
        "native-npm-modules"
      ],
      "scripts": {
        "rebuild": "electron-rebuild -v 11.2.1 -b -f -w msnodesqlv8"
      },
      "dependencies": {
        "msnodesqlv8": "^2.0.5",
        "mssql": "^6.2.1"
      },
      "devDependencies": {
        "electron-rebuild": "^2.0.1"
      }
    }
    

    TIP: This rebuild process is necessary for every team member. To ease this process, one team member may perform the rebuild process for each native module you use. And then they can commit the generated module to the repository and write a script that will simply copy this module to the respective directory in the node_modules directory.

    1. To rebuild the native module for vREST NG CLI, we recommend you to install that particular version of NodeJS against which vREST NG CLI binary is built. Then simply run the command npm install will build the native module. You may find the embedded NodeJS version of vREST NG CLI in our guide on Embedded Library Versions.
  2. Now you may use this dependency in the utility methods as per our guide on utiliity methods.