Showing posts with label Chrome. Show all posts
Showing posts with label Chrome. Show all posts

Friday, August 6, 2021

how to open a pdf file in chrome instead of download it?

 It is pretty straightforward to set the chrome to open the file instead of download it within the chrome setting.

here is the path the setting

chrome://settings/content/pdfDocuments

open the chrome and paste the above in the address bar. then select Open PDFs in Chrome





Wednesday, July 1, 2020

how to use build-in debugger to debug a Node.js appliation?

it is very important to trouble shot an issue or bug in the application development. i will show you how to use the debug tools that built into Node, that let you step through the code.

step 1. add debugger; before the line that you want to debug

 show: (reqresnext=> {
    let userId = req.params.id;
    User.findById(userId)
      .then(user => {
        debugger;
        res.locals.user = user;
        next();
      })
      .catch(error => {
        console.log(`Error fetching user by ID: ${error.message}`);
        next(error);
      });
  },



step 2. run node --inspect-brk main.js command in your project's terminal window to launch the build in debugger

C:\code\Node\unit5\recipe_app (master) (capstone@1.0.0)
λ node --inspect-brk main
Debugger listening on ws://127.0.0.1:9229/d66cdcb4-12df-4f71-80db-43d9c5ba6adc
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

step 3. launch the chrome browse and type chrome://inspect in the url window.









click on the inspect link. it will start breaking at the first line of main.js









you can either go to line by line with press F10 function or key or press the continue button to go the the line of code with debugger;












you can also go to the node tab under source section, then you can pick anything javascript files to set the breakpoint in order to inspect or trace the code and values








now you can easily fix the trouble code.








Tuesday, March 3, 2020

how to use Chrome DevTools to debug Node.js Code in development?

it should a very interesting topic for debugging the Node.js Code with Chrome.


1. you must have mocha package install in your node.js project.

npm install --save --save-exact mocha@2.47.5

after the installation, you will find this package in the package.json file.

"devDependencies": {
    "chai""3.5.0",
    "mocha""2.4.5"
  },

2. set up the test run command in the scripts section

 "scripts": {
    "test:debug""node --inspect node_modules/mocha/bin/_mocha --watch --no-timeouts"
  },

3. execute npm run test:debug to generate a web socket that Chrome can connect to for debugging.

PS C:\node\databases> npm run test:debug

> databases@1.0.0 test:debug C:\node\databases
> node --inspect node_modules/mocha/bin/_mocha --watch --no-timeouts

Debugger listening on ws://127.0.0.1:9229/433a7d4f-e829-47e0-a4b4-d6f6f87df9f0
For help, see: https://nodejs.org/en/docs/inspector



  parseRDF
    √ should be a function
    √ should parse RDF content


  2 passing (52ms)



4. Launch the Chrome browse and navigate to Chrome//inspect, then click on "Open dedicated DevTools for Node" then click on the inspect link to launch the chrome DevTool.









5. click on the source tab, then navigate to the filesystem. click on the add folder button to add your source code folder. interesting, after you complete this step. you have to close the  DevTools window and click on the inspect link again to force the breakpoint get hitting.









you have to click on the allow button in order to your source code.





6 set a breakpoint on the source code that you want to debug, then open a new terminal in visual studio code to run touch yourJavscript.js.

7. the breakpoint will be hit immediately, you can start to step through your code and debug it.