Page tree
Skip to end of metadata
Go to start of metadata

This API creates an Express callback from a Profound.js module which will receive the Express Request and Response objects as parameters. The returned function can be used with app.all(), app.get(), and similar Express APIs. If the configuration value connectorCredentials is set, this API can automatically sign on to IBM i. See Connecting to a Remote InstanceIf the instance is running on IBM i, a Profound UI session id can be passed on the request as a parameter named AUTH. If present, the API will automatically set the current user profile and library list of the connection to match the Profound UI session.

Parameters

  • module (string or function):
    • If a string is passed, it should contain the path to or name of the Profound.js module to be wrapped. The function exported as "run" in the wrapped Profound.js module will be called. 
    • In order to pass a function, profoundjs.require() must first be used to load a module.  
  • authenticate (boolean, optional) [deprecated] 
    Pass true to log on to IBM i. The default value is false.

    Deprecated Parameter

     In Profound.js 4.8.2 or higher, the authenticate parameter is ignored. Sign on to IBM i will occur should the Connector APIs be called by the program.

Examples

In start.js
var isWorker = profoundjs.server.listen();
if (isWorker) {
  var app = profoundjs.server.app;
  app.all("/products/:id", profoundjs.express("products.js"));
}
products.js
function products(req, res) {
  pjs.defineTable("productsp", { keyed: true, read: true });
  productsp.getRecord(Number(req.params.id));
  if (productsp.found()) {
    
    res.json({
      prid: prid,
      prname: prname.trim(),
      prdesc: prdesc.trim(),
      prprice: prprice,
      primage: primage.trim(),
      prqty: prqty,
      prcatid: prcatid
    });
    
  }
  else {    
    res.sendStatus(404);
  }
  
}
module.exports.run = products;
Use with function directly - in start.js
var isWorker = profoundjs.server.listen();
if (isWorker) {
  var app = profoundjs.server.app;
  var module = profoundjs.require("products.js");
  var myFunction = module.run;
  app.all("/products/:id", profoundjs.express(myFunction));
}

 

Video Tutorials