Tuesday, August 11, 2020

How to debug js code in third party npm package

Note

Before debugging the npm source code, you may want to try to run the npm command with verbose level log, the log may provide some details for you to solve the issue instead of debugging the code. To enable to verbose level log, run the npm command with below command

npm mycommand --loglevel verbose



When using third party npm package in your js app, sometimes you will need to debug the js code to figure out issues. 

Quite often, the third party npm package js code is minified, so as to load them faster. But during debug, you will want to load the no-minified js file. An easy way to do so is open the third party package.json file, and update main element's value to point to the debug version js entry point.

For example, to debug oidc-client.js, in package.json, make the below change

 "homepage": "https://github.com/IdentityModel/oidc-client-js",
  "license": "Apache-2.0",
  "main": "lib/oidc-client.js", "lib/oidc-client.min.js"
  "name": "oidc-client",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/IdentityModel/oidc-client-js.git"

  }, 

Sunday, August 2, 2020

How to view context.log content from azure portal

When implementing azure function app, it is quite often to call context.log method to write log for debug and trace function.

In order to view the log for a particular function in the Azure function app, first open azure portal, select the function app, and then select the function you are working on. Click the Monitor menu from blade, and select logs menu. 

A new console window will open and show "connected" when it is ready. Leave this portal window open, and from somewhere else triggers the function to be executed.  Then the context.log will show on the console window.