Run JavaScript in Visual Studio Code

后端 未结 18 1076
北恋
北恋 2020-11-30 17:04

Is there a way to execute JavaScript and display the results using Visual Studio Code?

For example, a script file containing:

consol         


        
18条回答
  •  长情又很酷
    2020-11-30 17:50

    Well, to simply run the code and show the output on the console you can create a task and execute it, pretty much as @canerbalci mentions.

    The downside of this is that you will only get the output and thats it.

    What I really like to do is to be able to debug the code, lets say Im trying to solve a small algorithm or trying a new ES6 feature, and I run it and there is something fishy with it, I can debug it inside VSC.

    So, instead of creating a task for it, I modified the .vscode/launch.json file in this directory as follows:

    {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "node",
            "request": "launch",
            "program": "${file}",
            "stopOnEntry": true,
            "args": [],
            "cwd": "${fileDirname}",
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "externalConsole": false,
            "sourceMaps": false,
            "outDir": null
        }
    ]
    }
    

    What this does is that it will launch whichever file you are currently on, within the debugger of VSC. Its set to stop on start.

    To launch it, press F5 key, in the file you want to debug.

提交回复
热议问题