Page 1 of 1

defineProc for getenv

Posted: Tue Jul 24, 2018 3:40 pm
by jleander
Has anyone done a pjs.defineProc for service program QSYS/QP0ZCPA procedure getenv? I could get around this with a RPG service program to wrap it, but I was curious if there was a cleaner way to just do within the Profound JS framework. As simple as the prototype is in RPG, the pointers with the *string without a true length definition are giving me difficulty to try to define it without causing errors when I actually try to call it.

Re: defineProc for getenv

Posted: Tue Jul 24, 2018 4:32 pm
by Scott Klement
Node.js has built-in support for environment variables. Can you use that?
https://nodejs.org/api/process.html#process_process_env

I would only consider calling an API like this if the built-in Node support didn't work for some reason.

Re: defineProc for getenv

Posted: Tue Jul 24, 2018 5:42 pm
by jleander
Hi Scott, I was trying to truly get the IBM i job level environmental variables, unfortunately the process.env object doesn't include those. We run 3 PUI servers with 3 associated PJS servers (DEV/UAT/PROD), so those variables (PROFOUNDJS_COMM_HOST and PROFOUNDJS_COMM_PORT) are set at the job level and I planned on using them to get the correct host:port to call from Rich display jobs to the corresponding PJS server's webservice without creating additional objects/data areas on our side.

In this specific use case, I have a Rich display PUI job calling a PJS module that would then be calling out to a PJS webservice, so I was trying to get the correct port within the PJS module. So for example if the PUI job is running on "server:8081" I'd want to be able to get to "server:8091/servicename".

Nothing I can't work around, and an RPG service procedure wrapper probably makes more sense as I will likely need the same information in RPG-driven rich displays as well, this was more curiosity than anything. Seemed like a nice complex example for the forums for people to reference!

Re: defineProc for getenv

Posted: Tue Jul 24, 2018 5:55 pm
by Scott Klement
That is, indeed, what process.env returns -- the job-level environment variables. (System-level variables are an IBM specific thing, so you typically won't find routines for system-level variables outside of IBM APIs. But job-level is available on almost all operating systems out there, Windows, Unix, MacOS, etc.)

However, it's very possible that the variables you want to retrieve are in a different job from the one where your Node.js code runs. In that case, you'd need to do something that makes a call to a program in that other job (such as an ILE procedure call).

Sounds like you're on the right track, here.