Page 1 of 1

Reusable JS Routines called from ProfoundAPI

Posted: Mon Feb 21, 2022 4:26 pm
by csharpest
As the first step of my Profound API I want to write a custom node step to run reusable routines...

Code: Select all

function runValidations(request, response) 
{
   var validator = require(validators.js");
   if (!validator.customerIsValid(request)) {
      //set failure variable
   } else {
      //set success variable
   }
}
In the same folder I have the validators.js file...

Code: Select all

function customerIsValid(request) 
{
   // reusable routine to do the actual validation
}
export default customerIsValid;
Is this possible? I am getting errors running the tester about module not being found:

Code: Select all

{
  "error": {
    "code": "MODULE_NOT_FOUND",
    "requireStack": [
      "c:\\Projects\\TestProjects\\ProfoundJS\\modules\\valTests\\...
     ],
    "message": "Cannot find module 'validators.js'  Require stack:  -

Re: Reusable JS Routines called from ProfoundAPI

Posted: Mon Feb 21, 2022 5:51 pm
by Scot Roach
This means that the file was not found within the server pathlist property.
1) You show that the module file "validators.js" is within a folder named "valTests" under the modules folder.
In the server configuration file (config.js), there is a pathlist property.
Ensure that folder is within that array, if not add it and restart the server.

2) I should also note that you should be using pjs.require("validators.js") instead of require("validators.js"). Our pjs.require API will lookup this module file based on this pathlist property.
https://docs.profoundlogic.com/x/VYDrAQ


Another way for creating reusable routines is called "Low-code Modules".
This does not create a web service but instead just the reusable logic as a module. These routines can then be consumed by Rich Display Screens, Profound APIs, as well as RPG programs.
https://docs.profoundlogic.com/x/YQZKB

I hope you find this information useful,
Scot Roach

Re: Reusable JS Routines called from ProfoundAPI

Posted: Tue Feb 22, 2022 9:40 am
by csharpest
Very useful. Thank you...