• how to notes - IBM i node.js debugging

    From m_warkentin@rogers.com@21:1/5 to intelogi...@gmail.com on Tue Jul 31 10:30:20 2018
    On Wednesday, 9 May 2018 17:44:23 UTC-4, intelogi...@gmail.com wrote:
    On Monday, October 23, 2017 at 9:07:22 AM UTC-5, Steve Richter wrote:
    some notes on how to use the fabulous chrome devtools to debug the javascript code run by node.js on the IBM i

    see the editor section for how to use a PC based editor to set yourself up to edit .js and .sh files that are in the IFS.

    Startup section has notes on starting node.js on the IBM i.

    sample section describes how to code, and then have node run a sample .js file.

    debug section shows how to start node in debug mode and then use chrome devtools to run the code in an interactive debugger.


    ... debug .... --------------- run node.js in debug mode ------------------

    -- see sample section. Perform those steps to have node run the sample1.js file.

    full writeup on using chrome devtools to debug node.js is here: https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27

    -- step1. in PASE shell, start node.js with --inspect option

    node --inspect --debug-brk /home/qpgmr/sample1.js

    result. get message saying debugger is listening on port

    Debugger listening on port 9229.

    -- step 2. Open about:inspect in Chrome
    -- in address bar of chrome browser, type "about:inspect" and press enter

    result. Chrome DevTools web page is displayed

    -- step 3. configure ip address of IBM i server where the node script is running

    click "configure"
    enter ip address of IBM i followed by port number from step 1.

    192.168.1.170:9229

    only have to enter this on first debug session.

    in Target section of DevTools web page is listed the node script being debugged.

    -- step 4. click "inspect" link to start interactive debugger

    result. Chrome interactive debugger is started. Shows .js script being debugged.

    click statement number in margin to set breakpoints. Press F8 to run, F10 to step
    thru code.

    -- step 5. Close debugger window

    once .js file being debugged has completed, message displayed in PASE shell:
    "waiting for debugger to disconnect ...".
    Shutdown the debugger window. Shell prompt is displayed.

    ... editor .... ------ set up to edit IFS based code using PC editor ---

    install visual studio code ( or any other PC based editor ) on PC.

    map the /home directory of the IFS to your PC

    to map a network drive to the IBM i you need to:
    - STRTCPSVR SERVER(*NETSVR)
    - need QUSRTOOL library. Follow instructions in TZLSINFO member of QUSRTOOL/QATTINFO

    start VS Code. Click File, open folder. Navigate to and select the mapped /home folder.

    to create a new file in the folder, hover mouse over folder name in the explorer view. Icons display next to folder name. Click the "new file" icon.

    When editing a .sh script file, make sure the "end of line sequence" is set to LF and not CRLF. In VSCode, look at the status line beneath the opened .sh file. If CRLF is display, click that "CRLF" text. Get prompt to change
    "end of line sequence". Click "LF" to change.

    ... sample .... ------------- code and run a sample node.js script -------

    -- see startup section. Run node.js startup script.

    -- using vscode, create a new .js file in an IFS folder. Call the script sample1.js
    -- place it in the /home/qgpmr folder.

    -- add the following code:

    var lines = [] ;
    lines.push(__dirname);
    lines.push(__filename) ;

    for( var ix = 0 ; ix < lines.length ; ++ix )
    {
    console.log( lines[ix]) ;
    }

    -- in the PASE shell, change directory to folder that contains the script.

    cd /home/qgpmr

    -- list contents of the folder. Then list the contents of the sample1.js file.

    ls
    cat sample1.js

    -- run node to run the sample1.js script file.
    -- Should see text output produced by the console.log statements.

    node sample1.js

    ... startup .... ------------- code node.js startup script -------------

    -- create PASE shell .sh file. store it in an IFS folder.
    -- example .sh name: /home/qpgmr/nodeStartup.sh

    -- make sure the lines of the .sh file are terminated by LF.
    -- CRLF line terminators causes .sh scripts to crash for
    -- inexplicable reasons.
    -- See basics section for notes on how to change 'end of line sequence'.

    #!/QOpenSys/bin/sh

    # set QIBM_MULTI_THREADED environment variable to Y. Has to do with thread # limit of QSHELL.
    export QIBM_MULTI_THREADED=Y

    # make global links for Node.js runtime. /QOpenSys/QIBM/ProdData/OPS/Node6/bin/nodever.sh 6

    # list the node and npm versions. Will verify that node and npm are in the path.
    node -v
    npm -v

    ... startup .... ------------------ run node.js startup script ----------

    -- call qp2term to start the PASE shell

    CALL QP2TERM

    -- change current directory to script folder

    cd /home/qgpmr

    -- run the startup script

    sh nodeStartup.sh

    Hey Steve, thank you for putting these instructions together! I'm trying to get remote debugging on the IBM i going for the first time. I've followed your first three steps, but in the fourth step, I never see the "inspect" link. The only thing I'm
    seeing is "Remote Target #(our IP)." Have you run into this before?

    Hi. I am just getting started on this too and solved the problem.

    You need to specify the IP address and port on the node --inspect statement in PASE, else it defaults to 127.0.0.1:9229.

    So CALL QP2TERM
    node --inspect-brk=10.1.12.66:9299 /home/mrtmgw/njs/sample5.js
    Debugger listening on ws://10.1.12.66:9299/7d7a5d91-dc19-4007-b4ce-3248d721e0a0
    For help see https://nodejs.org/en/docs/inspector
    Debugger attached.

    Then you should see the inspect button.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From intelogicaldesign@gmail.com@21:1/5 to All on Fri Aug 17 14:30:30 2018
    This helped a ton, thanks! Now I'm just having an issue getting it to handle breakpoints in Chrome Inspector. To summarize for others in the future...

    1. From the IBM i command line, run PASE.
    2. Run this from PASE: node --inspect-brk=<server ip address>:9229 index.js
    3. From Chrome web browser, specify URL of: chrome://inspect/
    4. Click Port Forwarding button (only need to do this once)
    a. set port(local) to: 8081
    b. set ip address and port (remote) same as step 2
    5. You should see an inspect link in Chrome.
    Remote Target > Target > inspect
    6. Click the inspect link to start debugging.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Steve Richter@21:1/5 to intelogi...@gmail.com on Sun Feb 24 08:05:02 2019
    On Friday, August 17, 2018 at 5:30:32 PM UTC-4, intelogi...@gmail.com wrote:
    This helped a ton, thanks! Now I'm just having an issue getting it to handle breakpoints in Chrome Inspector. To summarize for others in the future...

    1. From the IBM i command line, run PASE.
    2. Run this from PASE: node --inspect-brk=<server ip address>:9229 index.js 3. From Chrome web browser, specify URL of: chrome://inspect/
    4. Click Port Forwarding button (only need to do this once)
    a. set port(local) to: 8081
    b. set ip address and port (remote) same as step 2
    5. You should see an inspect link in Chrome.
    Remote Target > Target > inspect
    6. Click the inspect link to start debugging.


    this all worked for me. only exception being port forwarding was not necessary. Just had to click config and enter the IP address and port number on the IBM i server thru which the debugger --inspect traffic was to flow.

    The difference from last year is now we are running node 8. Node 8 giving us async and await. ( use YUM to install node 8 on the ibm i. )

    full writeup on using chrome devtools to debug node.js is here: https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27

    -- step 1. call qp2term to start the PASE shell

    -- step 2. make sure running version node 8 or greater PATH=/QOpenSys/pkgs/bin:$PATH
    node -v
    v8.15.0

    -- step3. run node command with debug options. Specify the ip address and port on
    -- the server thru which the --inspect traffic will flow.

    node --inspect-brk=192.168.1.170:9229 steve1.js

    get message saying debugger is listening on port

    Debugger listening on ws://192.168.1.170:9229/74ced1f7-e760-4c89-b7e1-b4e9da460f81

    -- step 4. In address bar of chrome browser, type "about:inspect" and press enter

    result. Chrome DevTools/devices web page is displayed

    -- step 5. configure ip address of the debugger on the IBM i server:

    click "configure"
    enter ip address of IBM i followed by port number from step 3.

    192.168.1.170:9229

    only have to enter this on first debug session.

    in Target section of DevTools web page is listed the node script being debugged.

    -- step 5. click "inspect" link to start interactive debugger

    result. Chrome interactive debugger is started. Shows .js script being debugged.

    click statement number in margin to set breakpoints. Press F8 to run, F10 to step
    thru code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)