If you run node you get into interactive mode, you can inspect, execute functions etc. But once you run a function from interactive mode or from the OS shell, can you pause execution and go to interactive mode deliberately?
In browser you can use debugger keyword, but in Node.js debugger does nothing for me.
When my software fails and I want to quickly figure it out, I add a debugger instruction where I want the debugger to break and do:
node debug [script I want to debug]
Note that it is node debug, not node --debug. The latter also starts a debugger but it is one that waits on a port for some UI to connect.
Doing the above will cause the debugger to stop before executing your software. Type c to let it continue. It will next stop where you put your debugger statement. If you want to evaluate things dynamically you can use the repl command.
If you do it this way, you don't need any extra tools. The documentation is here.
try the node-inspector, you can debug your app with chrome developer tool
1.install and start node-inspector
npm install -g node-inspector
node-inspector &
2.start your app with debug parameter (if you want to break in the first line, replace the parameter to --debug-brk
node --debug server.js
3.open debug link in Chrome
open http://127.0.0.1:8080/debug?port=5858
Related
I updated VS code to version 1.59.1 and Node debugging no longer works-- I was on a July 2020 build before today. I use nvm to toggle between versions and my nvm default is Node 12.22.
If I run 'node --inspect-brk...' (which I used to do) in a VS code terminal things just hang with a 'debugger listening..' message. If I run 'node --inspect' the program runs, also with a 'debugger listening..' message but no breakpoints are respected. (What's the difference by the way, between inspect and inspect-brk?)
After installing the latest VS code and opening it a dialog appeared saying Node 10 is in my path and so auto-attaching would no longer work. And yes, Node 10 is part of my nvm options, but I'm using Node 12 now via nvm. (That dialog no longer appears now when I open VS Code, for some reason.)
I have the VS code 'auto attach' setting set to 'only with flag'. I've tried the 'always' option too but no luck. I've closed and reopened VS code numerous times to see if a changed setting will work but it hasn't so far. If anyone knows something I may have missed or knows what's what, I'm happy to hear suggestions.
A couple things you can try when the auto-attach doesn't work:
set auto-attach to disabled, then back on 'with flag'
check with env that the NODE_OPTIONS environment variable looks something like:
NODE_OPTIONS=--require /home/me/.vscode-server/data/User/workspaceStorage/dc520ffe0268148fad350d767ccf9350-1/ms-vscode.js-debug/bootloader.js
If not, then it helps to restart your vscode terminal, your bash, etc, until it does.
--inspect-brk tells NodeJS to wait for a debugger to attach before starting the program.
--inspect enables debugging but doesnt wait for a debugger
With vscode's auto-attach, you should use --inspect. It will attach automatically as soon as the program starts.
In the Node (v16.7.0) REPL, Node tries to evaluate my statement before I've finished typing it. For example, if I type 2 + 2, it displays a faint 4 on the next line before I hit the Enter key. Is there a way to disable this behavior? For most cases, it's not a problem; but when I'm performing expensive operations, the REPL lags or freezes up as I'm trying to finish typing my statement. To be clear, the problem is not that the interpreter is printing the output; it's that it's trying to evaluate my statement before I finish typing it. Thanks in advance for your help!
The REPL library calls that a preview (search for preview in the link for more info). I'm not aware how to launch the default node REPL with command line options (or some other kind of configuration options) so that previews are not shown, but the REPL itself is a library you can use, with all the defaults (or whatever you prefer) and removing previews - for this check the REPL library options.
A basic example is creating this script:
#!/usr/bin/env node
const repl = require('repl');
repl.start({
preview: false
});
Make sure you also have it as executable (in Linux/Mac from the command line it would be with chmod +x name-of-repl-script from the terminal), and well, run that script instead of node directly.
Alternatively you can run the script with node name-of-repl-script (here, assuming node is the NodeJS REPL executable and that it's in the path).
I've been trying to get the Nuclide debugger set up in atom. I've installed the atom-ide-ui and atom-ide-debugger-node packages, and can see and open the Nuclide debugger. However, I want to run yarn test_shared as my command, but the debugger only seems to allow a one word command like node or yarn, without any arguments.
Running this would work, but won't actually run my test suite:
This is the command I want to run, but when I launch the debugger it throws this error: Failed to start debugger process: Attribute 'runtimeExecutable' does not exist ('{path}').
Has anyone else found a way to set this up?
I'm using Node.js in VScode. Say my run command is node index.js. As I run command various console.log statements print during course now I want to clear console log without stopping current node process. In existing case To clear the console I have to stop the running process using Ctrl+c. use clear command in terminal to clear screen and again run the process using node index.js. My question is there any method by using which i can clear terminal window without stopping current node process.
You can use console.clear() function in your node program. If you want to clear vscode terminal window, just click by right mouse on terminal and select Clear (shortcut Ctrl + K)
I am running node inspector and trying to run commands in the console.
However, I cannot run them. Instead of running, hitting enter goes to a new line.
Using any other console in chrome works fine, just not Inspector's.
Have tried restarting node and inspector. Any ideas how to fix this?
It seems like Chrome v54, v56 are having this issue for both mac and windows. The easiest solutions so far is downgrading your chrome to v51, and I think some one is working on a PR to fix this.
You can download V51 from here
http://google-chrome.en.uptodown.com/mac
===========================================================================
Another work around is to use command
node --inspect --debug-brk index.js
After running that, goto chrome, open
chrome://inspect you will see a page like this
Find the target and click the inspect, a debugger will be attached automatically and everything works from there. Just like it used to be in node-inspect, and the console works!
read this for more information
http://www.mattzeunert.com/2016/06/01/node-v8-inspector-inspect.html