Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Last active September 3, 2023 16:54
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joseluisq/29486ca0cce78019bcab696eaff7b090 to your computer and use it in GitHub Desktop.
Save joseluisq/29486ca0cce78019bcab696eaff7b090 to your computer and use it in GitHub Desktop.
A simple NodeJS App debugging example in VS Code using Nodemon.

NodeJS debugging in VS Code with Nodemon

A simple NodeJS App debugging example in VS Code using Nodemon.

Note: Feel free to customize .vscode/launch.json and ./nodemon.json files.

Install

yarn add nodemon --dev

Debugging

Add debug to your package.json script section:

+ "debug": "nodemon --debug server.js",

Run Nodemon:

yarn debug

Finally, select the attach configuration before in your VS Code and go to Debug > Start debugging F5

⚡️ Enjoy!

{
"version": "1.0.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": null,
"args": [],
"stopOnEntry": false,
"runtimeArgs": [ "--nolazy" ],
"preLaunchTask": null,
"env": {
"NODE_ENV": "development",
"LOG_LEVEL": "debug"
},
"console": "internalConsole",
"program": "${workspaceFolder}/server.js",
"outFiles": []
},
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outFiles": [],
"localRoot": "${workspaceFolder}",
"remoteRoot": null
}
]
}
{
"env": {
"TZ": "UTC",
"NODE_ENV": "development",
"LOG_LEVEL": "debug"
},
"watch": [ "./src" ],
"ext": "js",
"signal": "SIGTERM"
}
{
"env": {
"TZ": "UTC",
"NODE_ENV": "development",
"LOG_LEVEL": "debug"
},
"watch": [
"src"
],
"ext": "ts",
"ignore": [
"src/**/*.spec.ts"
],
"signal": "SIGTERM",
"exec": "npm run lint && ts-node -r tsconfig-paths/register src/main.ts"
}
@winuxue
Copy link

winuxue commented Dec 7, 2017

what about if the code is written in Typescript?

@joseluisq
Copy link
Author

joseluisq commented Dec 22, 2017

@winuxue It's already supported via nodemon too.
Checks the following link:
microsoft/vscode#10560

Bonus:
https://github.com/Microsoft/vscode-recipes/

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment