Stumbling startup with node.js on IBM i

My 7.2 upgrade was done specifically to get going with an “officially” supported version of node.js.  Installing 5733OPS is a no brainer (either RSTLICPGM or just using the option to install a licensed program in the LICPGM menu will work).  Node worked great.  Already creating much mayhem with socket.io, express.js, and a bunch of other stuff I will eventually break.  The problem I had is that I could only do this stuff when I was in the Node/bin folder.  Otherwise I would see:

node -v
exec(): 0509-036 Cannot load program node because of the following errors:
0509-150   Dependent module libstdc++.a(libstdc++.so.6) could not be loaded.
0509-022 Cannot load module libstdc++.a(libstdc++.so.6).
0509-026 System error: A file or directory in the path name does not exist.

What?   I am only a noob when it comes to *NIX environments and I know there are a bunch of moving parts that need to be correctly aligned.  I thought my PATH was the only thing I needed to look at but I was missing something essential: The LIBPATH environment variable.  Many executables share functionality so the “helper” objects need to be in the PATH as well so they can be found (like service programs or DLL’s) so the LIBPATH needs to be set as well.  My “Brogrammer” in the Open Source space, Aaron Bartell, turned me on to that fact and he proposes a couple of solutions.  You could just manually set the PATH and LIBPATH:

[Depending on the shell you use you can either do it in one step like this]

export PATH=/QOpenSys/QIBM/ProdData/Node/bin:$PATH
export LIBPATH=/QOpenSys/QIBM/ProdData/Node/bin:$LIBPATH

[or your shell may require that you do it in two steps like this]

PATH=/QOpenSys/QIBM/ProdData/Node/bin:$PATH
export PATH
LIBPATH=/QOpenSys/QIBM/ProdData/Node/bin:$LIBPATH
export LIBPATH

Or you could create a script and just run it when needed.  Here are some screen shots that show the problem and solutions:

node_error

So the problem occurs in #1 above even though I have the node/bin folder on my path (#2).  If I check the LIBPATH environment variable, it is empty so I append the path to the shared library to the LIBPATH (which just happens to be the same as the node/bin folder).  Adding the path and exporting it makes it available to my environment so now when I run node – v I get the version listed rather than an error.  Nice!  Aaron pointed me here to find this info and recommended that I post questions here so that others might benefit.  Agreed!  But I’ll probably also post here since I tend to forget where I posted solutions to my issues.

The script to do this is simple as well.  You should have a folder in your IBM i “home” folder under your IBM i user name.  Mine would be /home/PETE/  You could either use this command on IBM i:

EDTF ‘node_env.sh’   (you can call the script whatever you want) :

edtf_node_env

If you want to up your *NIX geek cred, you could use vi in SSH (or call qp2term):

vi /home/PETE/node_env.sh

vi_node_env

However you get there!  Then when you are in the console you can just execute the script:

node_script_fix

So, all is well.  Just remember to execute the node_env.sh script, OR, if you are going to launch a node server instance using CL, I usually create a script and then just execute the script in the CL program so you don’t have to have multiple entries to set the environment.  Just do your heavy lifting in the script, let your CL do the easy part.

So, that’s it!  There is probably more detail here than most folks need but for folks who are new to open source on IBM i, a little extra instruction can fill in a lot of blanks.

 

This entry was posted in Programming and tagged , , . Bookmark the permalink.