Run JavaScript in Visual Studio Code

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

    It's very simple, when you create a new file in VS Code and run it, if you already don't have a configuration file it creates one for you, the only thing you need to setup is the "program" value, and set it to the path of your main JS file, looks like this:

    {
        "version": "0.1.0",
        // List of configurations. Add new configurations or edit existing ones.  
        // ONLY "node" and "mono" are supported, change "type" to switch.
        // ABSOLUTE paths are required for no folder workspaces.
        "configurations": [
            {
                // Name of configuration; appears in the launch configuration drop down menu.
                "name": "Launch",
                // Type of configuration. Possible values: "node", "mono".
                "type": "node",
                // ABSOLUTE path to the program.
                "program": "C:\\test.js", //HERE YOU PLACE THE MAIN JS FILE
                // Automatically stop program after launch.
                "stopOnEntry": false,
                // Command line arguments passed to the program.
                "args": [],
                // ABSOLUTE path to the working directory of the program being debugged. Default is the directory of the program.
                "cwd": "",
                // ABSOLUTE path to the runtime executable to be used. Default is the runtime executable on the PATH.
                "runtimeExecutable": null,
                // Optional arguments passed to the runtime executable.
                "runtimeArgs": [],
                // Environment variables passed to the program.
                "env": { },
                // Use JavaScript source maps (if they exist).
                "sourceMaps": false,
                // If JavaScript source maps are enabled, the generated code is expected in this directory.
                "outDir": null
            }, 
            {
                "name": "Attach",
                "type": "node",
                // TCP/IP address. Default is "localhost".
                "address": "localhost",
                // Port to attach to.
                "port": 5858,
                "sourceMaps": false
            }
        ]
    }
    

提交回复
热议问题