Is there a way to debug a single javascript file step by step without launching a node server?
For example seed files by knex.
Node is definitely needed, but I do not know how to start the VSC debugger with only the file.
There are two ways to achieve this:
Just add launch.json
and give your file_name
. and start
debugging.
For example, If your file_name
is index.js
. create a folder
called .vscode
and inside this folder create launch.json
, structure looks like this:
main_folder
|___ index.js
|___ .vscode
|___ launch.json
and provide path as below in launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Current Opened File",
"program": "${file}"
}
]
}
The second option is to create a package.json
and give your file an entry point. when you press F5, vscode
will consider this file as starting point.
main_folder
|___ index.js
|___ package.json
you can create package.json
manually or can create it using npm init
, This will ask you a bunch of questions, and then write a package.json
for you.
{
"name": "application_name",
"version": "0.0.0",
"description": "for single page debugging",
"main": "index.js",
"author": "",
"license": "ISC"
}
To launch(debug) currently opened/active *.js file, you should have the following configuration in your launch.json
file:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Current Opened File",
"program": "${file}"
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With