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.
seeing is "Remote Target #(our IP)." Have you run into this before?... 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
node --inspect-brk=10.1.12.66:9299 /home/mrtmgw/njs/sample5.jsDebugger listening on ws://10.1.12.66:9299/7d7a5d91-dc19-4007-b4ce-3248d721e0a0
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.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 80:48:25 |
Calls: | 6,658 |
Calls today: | 4 |
Files: | 12,203 |
Messages: | 5,333,189 |
Posted today: | 1 |