简体   繁体   中英

How to automatically run a Node.js program using VSCode?

I was wondering whether there is a way to execute a Node.js program using some keyboard shortcut in Visual Studio Code.

For instance, while I am coding in the editor, instead of having to manually open the Integrated Terminal in Visual Studio Code and then type let's say node app.js , can I just configure a key to automatically do this?

Below shown is an illustration of what I want:

在此处输入图片说明

I want to run the file app.js in the terminal without having to go there again and again and type node app (or even by using the up arrow key to bring the last entry from the terminal's history).

Note: I found one way of doing so and that is to go to the Debug console . But sometimes, it doesn't display full results. For instance, when logging a module, it displays one line with a caret which can be used to inspect details of the logged object further, but when I press the caret, it says that there is no debugger to view the object .

You can create a shell task or an npm task that runs node app.js . You can then bind a hotkey for running a task in the VS Code key binding settings. The npm extension should automatically detect every script in the package.json file and provide them as a task if the task.autoDetect setting is set to on. You can simply add a start script that runs node app.js . I have then set up a hotkey that reruns the latest task: { "key": "ctrl+rb", "command": "workbench.action.tasks.reRunTask" },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM