1

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:

enter image description here

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.

2

1 Answer 1

2

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" },

Sign up to request clarification or add additional context in comments.

2 Comments

The npm handles tasks for node.js automatically. I've added a rough overview as an edit.
I didn't get the last comment you wrote. Could you please explain it a bit further?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.