Front-end debugging 2

1. Debugging with chrome (node.js)

example:

const fs = require('fs/promises');

(async function() {
    const fileContent = await fs.readFile('./package.json', {
        encoding: 'utf-8'
    });
    
    await fs.writeFile('./package2.json', fileContent);
})();

1. First run node index.js:
2. Then start in debug mode, add a --inspect-brk parameter:
node --inspect-brk ./index.js
--inspect is started in debug mode, --inspect-brk is started in debug mode and breaks on the first line.
3. The debugged server is as shown in the picture above: the part outlined in red

Next, debug nodejs with Chrome:

  1. Open chrome://inspect/#devices , and all the targets that can be debugged are listed below, that is, the ws server:

The node debugging service runs on port 9229 by default, but it can also be changed

Just add its port to the configuration:

  1. Click inspect to debug

2. Debugging with VsCode (node.js)

1、

2、

3、

The first line is broken, you can add a stopOnEntry configuration:

4, you can debug

Three, nine kinds of JS scope

  • Global scope : Global scope, which is window in the browser environment and global in the node environment

  • Local scope : local scope, or function scope

  • Script scope : global variables declared by let and const will be saved in script scope, these variables can be accessed directly, but cannot be accessed through window.xx

  • Module scope : In fact, strictly speaking, this is also a function scope, because when node executes it, it will wrap a layer of functions, which is a special function scope, with variables such as module, exports, and require

  • Catch Block scope : The scope of the catch statement has access to the error object

  • With Block 作用域:with 语句会把传入的对象的值放到单独的作用域里,这样 with 语句里就可以直接访问了

  • Closure 作用域:函数返回函数的时候,会把用到的外部变量保存在 Closure 作用域里,这样再执行的时候该有的变量都有,这就是闭包。eval 的闭包比较特殊,会把所有变量都保存到 Closure 作用域

  • Eval 作用域:eval 代码声明的变量会保存在 Eval 作用域

Guess you like

Origin blog.csdn.net/weixin_52993364/article/details/128918779