Node, yum, npm, PATH = mess!

Issue #65 resolved
Michael Haston created an issue

I’m just getting started with Node on the IBM i. I’ve installed a few npm modules and have some sample scripts working, but I have a feeling my PATHs are a mess and I have stuff installed all over the place. What’s the best way to make a clean start.

For instance, at one point depending on how my path was setup node -v would tell me version 8 or 12!

Here are the two ways I was trying to set my PATH:

export PATH=/QOpenSys/pkgs/bin:$PATH;

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

Our data center installed Node and it doesn’t seem to be where earlier versions suggested it would be.

Any suggestions at trying to clean up and start fresh?

Comments (13)

  1. Michael Haston reporter

    Also, I’m getting a lot of these errors even though I just saw libatomic installed.

    -bash-4.4$ npm -v
    Could not load program node:
    Dependent module libatomic.a(libatomic.so.1) could not be loaded.
    Could not load module libatomic.a(libatomic.so.1).
    System error: No such file or directory

    I’ll change my PATH and then get this:

    -bash-4.4$
    -bash-4.4$ export PATH=/QOpenSys/QIBM/ProdData/Node/bin:$PATH
    -bash-4.4$ export LIBPATH=/QOpenSys/QIBM/ProdData/Node/bin:$LIBPATH
    -bash-4.4$ npm -v
    /QOpenSys/QIBM/ProdData/Node/lib/node_modules/npm/bin/npm-cli.js:84
    let notifier = require('update-notifier')({pkg})
    ^^^^^^^^
    SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

  2. Jesse G

    Greetings!!

    Unfortunately, the history of open source has enough complexity to cause some messes such as this!

    First off…. Some input on WHERE to check for these settings…. Here are places where you can check for the setting of PATH and LIBPATH for your user profile:

    • $HOME/.profile
    • $HOME/.qshrc
    • $HOME/.bash_profile

    And there are several other less-commonly-used locations. You could try to catch any others by running grep PATH $HOME/.* and eye-balling the results. QSH on green screen will often have a different environment than an SSH terminal because it doesn't run the .profile.

    Second, global settings for all users are often stored in /QOpenSys/etc/profile, so you might have PATH or LIBPATH set there.

    That being said, here are some pointers on the WHAT I would advise:

    Also, note that some shells require you to expert the PATH in two steps, so:

    PATH=/QOpenSys/pkgs/lib/nodejs10/bin:/QOpenSys/pkgs:$PATH
    export PATH
    

    A good place to put the above two lines would be in your $HOME/.profile (for just you) or /QOpenSys/etc/profile (for everyone).

    I have seen cases where green-screen QSH wouldn't automatically run the .profile commands, so I had to explicitly run source $HOME/.profile. I’m not sure what’s up with that, but green-screen is not recommended anyway.

    Hope this helps. Feel free to come back with any questions.

  3. Jesse G

    Also, the libatomic failures are a side effect of unnecessarily setting LIBPATH (and setting it to an incorrect location). The correct versions of Node.js will find it in /QOpenSys/pkgs/lib (but again, it will do so without the user setting LIBPATH)

  4. Michael Haston reporter

    Jesse - thanks for all the quick and in depth information. I have a lot to dig through. Just fixing my path in those two profile files has eliminated all of the errors I was previously running into.

    One question I have, when you say uninstall 5733-OPS, I don’t see where you say reinstall it. So I should not reinstall 5733-OPS?

  5. Michael Haston reporter

    A few more questions?

    • Are yum and npm similar in what they do? As a tool to install/uninstall/upgrade packages? Or am I mixing apples and oranges?
    • I installed pm2 and have a server running, but now I can’t run any pm2 command. I thought installing it again would clean things up, but I received these messages:

    -bash-4.4$ npm i pm2
    npm WARN saveError ENOENT: no such file or directory, open '/home/MHASTON/package.json'
    npm WARN enoent ENOENT: no such file or directory, open '/home/MHASTON/package.json'
    npm WARN MHASTON No description
    npm WARN MHASTON No repository field.
    npm WARN MHASTON No README data
    npm WARN MHASTON No license field.
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"aix","arch":"ppc64"})

    Thanks again.

  6. Jesse G

    You should absolutely not install 5733-OPS (again, unless you have production code using it). 5733-OPS is not supported and the Node.js it ships has already passed end of life. The strategic path is RPMs only (http://ibm.biz/ibmi-rpms), and you can also get support for Node.js and other RPMs (http://ibm.biz/ibmi-oss-support).

    Yum and npm are similar, except that:

    • Yum installs open source packages for the system, including language runtimes such as Node.js
    • Each language has its own toolset for sorting out dependencies, file locations, etc. for community modules. (Node.js has npm, Python has pip, R has cran, PHP has pecl, Perl has cpan)

    npm has two different types of installations:

    1. Global installations, which are for command-line utilities such as pm2 or node-gyp (used for building native add-ons). You'd install with npm install -g pm2 (the -g tells it it’s a global install).
    2. Local installations, which are really local to the current directory and therefore your application. This is for modules that your application will use. You'd run this from your application directory (where you've run an npm init to create application metadata in a package.json file). Local installations are the default, so running npm without -g gets you a local install.

    Your warnings, in particular, are because you're asking for a local install, but you haven't run npm init in the current directory. Since pm2 is something you’d want to run from the command line, you’ll want to do a global install. After which, it should be available on the command line once PATH is set up to include your node version-specific path (for instance /QOpenSys/pkgs/lib/nodejs10/bin from my earlier update)

  7. Michael Haston reporter

    I never do any of the installs or uninstalls, so I should get rid of all of these? We have nothing in production yet.

    5733OPS *BASE IBM i Open Source Solutions
    5733OPS 1 Node.js v0 (deprecated)
    5733OPS 3 Chroot with gcc
    5733OPS 4 Python 2.7
    5733OPS 7 Tools
    5733OPS 10 Node.js v6

    I have a small Node script on a virtual server pulling information from AD. I’ll be able to move that over to our IBMi. We’ll be making REST API calls from our ERP using a CyberSource Node toolkit. I’m sure we’ll find several more uses for all of this!

    Thank you very much.

    Mike

  8. Michael Haston reporter

    Thank you for all of your help. 5733OPS in uninstalled. I went through your migration documents.

    One thing that differed for me, probably because I created a mess, is my PATH is set to:

    PATH=/QOpenSys/pkgs/lib/nodejs10/bin:/QOpenSys/pkgs:/QOpenSys/pkgs/bin:$PATH
    

    I think that was the only way to get the yum, node and npm commands recognized.

  9. Michael Haston reporter

    How familiar are you with PM2? I made a change to my script and I can’t get the server started again. PM2 says it’s online, but I can’t get to it. The log tells me:

    internal/modules/cjs/loader.js:584
        throw err;
        ^
    
    Error: Cannot find module '/QOpenSys/QIBM/ProdData/Node/lib/node_modules/pm2/lib/ProcessContainerFork.js'
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
        at Function.Module._load (internal/modules/cjs/loader.js:508:25)
        at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
        at startup (internal/bootstrap/node.js:283:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
    internal/modules/cjs/loader.js:584
        throw err;
        ^
    

    Process ContainerFork is actually in /QOpenSys/pkgs/bin/node_modules/pm2/lib

  10. Jesse G

    Sorry, I had a typo in my earlier help, glad you figured out that /QOpenSys/pkgs/bin needs to be in your path, not /QOpenSys/pkgs!

    Now that your environment is set up correctly, you should be able to remove the pm2 currently installed (which may require you to explicitly delete it from /QOpenSys/usr/bin/pm2) and reinstall globally.

  11. Log in to comment