Reputation: 1859
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.
Upvotes: 1
Views: 2845
Reputation: 36
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+r b", "command": "workbench.action.tasks.reRunTask" },
Upvotes: 2