Run JavaScript in Visual Studio Code

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

    The shortcut for the integrated terminal is ctrl + `, then type node .

    Alternatively you can create a task. This is the only code in my tasks.json:

    {
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "node",
    "isShellCommand": true,
    "args": ["${file}"],
    "showOutput": "always"
    }
    

    From here create a shortcut. This is my keybindings.json:

    // Place your key bindings in this file to overwrite the defaults
    [
    {   "key": "cmd+r",
    "command": "workbench.action.tasks.runTask"
    },
    {   "key": "cmd+e",
    "command": "workbench.action.output.toggleOutput"
    }
    ]
    

    This will open 'run' in the Command Pallete, but you still have to type or select with the mouse the task you want to run, in this case node. The second shortcut toggles the output panel, there's already a shortcut for it but these keys are next to each other and easier to work with.

提交回复
热议问题