000debugging - Getting Started - Node - Js
000debugging - Getting Started - Node - Js
Security Implications
Since the debugger has full access to the Node.js execution
environment, a malicious actor able to connect to this port
may be able to execute arbitrary code on behalf of the
Node.js process. It is important to understand the security
implications of exposing the debugger port on public and
private networks.
Exposing the debug port publicly is unsafe
If the debugger is bound to a public IP address, or to 0.0.0.0,
any clients that can reach your IP address will be able to
connect to the debugger without any restriction and will be
able to run arbitrary code.
By default node --inspect binds to 127.0.0.1. You explicitly
need to provide a public IP address or 0.0.0.0, etc., if you
intend to allow external connections to the debugger. Doing
so may expose you to a potentially significant security
threat. We suggest you ensure appropriate firewalls and
access controls in place to prevent a security exposure.
See the section on 'Enabling remote debugging scenarios'
on some advice on how to safely allow remote debugger
clients to connect.
Inspector Clients
A minimal CLI debugger is available with node inspect
myscript.js . Several commercial and open source tools can
chrome-remote-interface
Library to ease connections to Inspector Protocol
endpoints.
Gitpod
Start a Node.js debug configuration from the Debug
Command-line options
The following table lists the impact of various runtime flags
on debugging:
Flag Meaning
Enable inspector agent; Listen on default
--inspect
address and port (127.0.0.1:9229)
Enable inspector agent; Bind to address or
--inspect=
hostname host (default: 127.0.0.1); Listen
[host:port]
on port port (default: 9229)
Enable inspector agent; Listen on default
--inspect-brk address and port (127.0.0.1:9229); Break
before user code starts
Enable inspector agent; Bind to address or
--inspect-brk= hostname host (default: 127.0.0.1); Listen
[host:port] on port port (default: 9229); Break before
user code starts
Spawn child process to run user's script
node inspect
under --inspect flag; and use main process
script.js
to run CLI debugger.
Spawn child process to run user's script
node inspect --
under --inspect flag; and use main process
port=xxxx
to run CLI debugger. Listen on port port
script.js
(default: 9229)
Legacy Debugger
The legacy debugger has been deprecated as of Node.js
7.7.0. Please use --inspect and Inspector instead.
When started with the --debug or --debug-brk switches in
version 7 and earlier, Node.js listens for debugging
commands defined by the discontinued V8 Debugging
Protocol on a TCP port, by default 5858 . Any debugger client
which speaks this protocol can connect to and debug the
running process; a couple popular ones are listed below.
The V8 Debugging Protocol is no longer maintained or
documented.
Built-in Debugger
Start node debug script_name.js to start your script under the
builtin command-line debugger. Your script starts in another
Node.js process started with the --debug-brk option, and the
initial Node.js process runs the _debugger.js script and
connects to your target.
node-inspector
Debug your Node.js app with Chrome DevTools by using an
intermediary process which translates the Inspector
Protocol used in Chromium to the V8 Debugger protocol
used in Node.js.
Copyright OpenJS Foundation and Node.js contributors. All rights reserved. The OpenJS Foundation has registered trademarks
and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List.
Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of
their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Trademark Policy | Privacy Policy | Code of Conduct | Security Reporting