Run JavaScript in Visual Studio Code

后端 未结 18 1087
北恋
北恋 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:40

    This may now be the easiest, as of v1.32:

    {
        "key": "ctrl+shift+t",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "node '${file}'\u000D" }
      }
    

    Use your own keybinding.

    See Release notes: sendSequence and variables.

    With vscode v1.32 you can sendSequence to the terminal using variables like ${file}, which is the current file. If you want some other path there, replace ${file} with your pathname in the keybinding above.

    The \u000D is a return so it will run immediately.

    I added 's around the ${file} variable in case your file path has spaces in it, like c:Users\Some Directory\fileToRun

提交回复
热议问题