Languages
[Edit]
EN

VS Code - debug js file with Node.js

6 points
Created by:
Shri
8550

In this short article, we would like to show you how debug JavaScript file with Node.js in VS Code.

The below example shows how to configure VS Code via launch.json file to debug my_script.js file Node.js.

Note: if the green button is not available try to create .vscode/launch.json file manually.

The way how to debug js file with Node.js.
The way how to debug js file with Node.js.

Project structure:

/C/
 |
 +-- Project/
      |
      +-- .vscode/
      |    |
      |    +-- launch.json
      |
      +-- my_script.js

Example .vscode/launch.json config content:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "My Script",
            "program": "my_script.js"
        }
    ]
}

 

Multiple configurations with different arguments

This section shows how to use multiple configurations with passed different arguments.

To pass arguments from command line it is necessary to execute:

node my_script.js "arg_1" "arg_2" "arg_3" "arg_N"

In debug mode is similar, it is necessary just to add "args" property inside launch.json file, e.g.

"args": ["arg_1", "arg_2", "arg_3", "arg_N"]

Example .vscode/launch.json config file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "My Script - John/Secret_1@345",
            "program": "my_script.js",
            "args": ["John", "Secret_1@345"]
        },
        {
            "type": "node",
            "request": "launch",
            "name": "My Script - admin/admin",
            "program": "my_script.js",
            "args": ["admin", "admin"]
        }
    ]
}

 

See also

  1. VS Code - debug with npm run 

Alternative titles

  1. VSCode - debug js file with Node.js
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Visual Studio Code

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join