Reusable JS Routines called from ProfoundAPI

Use this board for starting discussions, asking questions, and giving advice on Web programming for the IBM i platform (and predecessors.)
csharpest
New User
Posts: 4
Joined: Mon Feb 21, 2022 3:48 pm
First Name: Bill
Last Name: Upton
Company Name: ManhattanLife
State / Province: Texas
Country: United States
Contact:

Reusable JS Routines called from ProfoundAPI

Post 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:  -
User avatar
Scot Roach
Profound Logic Staff Member
Posts: 2
Joined: Wed Jan 02, 2019 4:05 pm
First Name: Scot
Last Name: Roach
Company Name: Profound Logic Software, Inc.
Phone: 4073103816
Address 1: 3521 Fountain City Rd
City: De Soto
State / Province: Missouri
Zip / Postal Code: 63020
Country: United States
Contact:

Re: Reusable JS Routines called from ProfoundAPI

Post 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
csharpest
New User
Posts: 4
Joined: Mon Feb 21, 2022 3:48 pm
First Name: Bill
Last Name: Upton
Company Name: ManhattanLife
State / Province: Texas
Country: United States
Contact:

Re: Reusable JS Routines called from ProfoundAPI

Post by csharpest »

Very useful. Thank you...
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests