vscode调试使用nodejs纯调试javascript

vscode调试使用nodejs纯调试javascript

其实就是跟自己较劲,可以写个包含js的html进行调试,不用这么麻烦做单独调试!不过个人开发就是喜欢语言有各自的环境!

在本地目录编写好js以后,按运行调试

然后编辑器会自动生成.vscode目录,并且下面会生成launch.json文件,并弹出需要自己扩充修改

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "启动程序",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/test.js"
        }
    ]
}

然后按需要修改

{
 
    "version": "0.2.0",
    "configurations": [{
            "name": "谷歌浏览器", //运行html文件,用谷歌浏览器打开
            "type": "chrome",
            "request": "launch",
            "url": "${file}",
            "sourceMaps": true,
            "webRoot": "${workspaceRoot}"
        },
        {
            "name": "nodeLauch", //单独调试js,即可以直接运行js
            "type": "node",
            "request": "launch",
            "program": "${file}", //这个配置成你要调试的文件、${file}当前打开的文件
            "stopOnEntry": false,
            "args": [],
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "console": "internalConsole",
            "preLaunchTask": "",
            "sourceMaps": false,
            "outDir": null
        }
    ]
}

其他参数有空再研究,如果用html调试,可以用alert进行函数输出查看(相当与print),如果纯js调试,我暂时只想到console.log()方法在终端输出结果,如有其他方法,烦请大虾指正!

Reference:

https://blog.csdn.net/freeking101/article/details/88427375

https://www.cnblogs.com/zenronphy/p/12233715.html

https://www.jianshu.com/p/d30cf3097e1a

https://blog.csdn.net/g0415shenw/article/details/84894719

评论

暂无评论