alexa

Running commands while a Node.js server is live ?

Running commands while a Node.js server is live ?

Basically, it sounds like you're looking for a Node.js equivalent of the browser console that's available to browser-hosted JavaScript.

Node.js doesn't provide one directly (it does have a REPL that may serve your needs; see but many IDEs include a "Debug Console" (that's what VS Code calls it) or similar that you can use when running the code in debug mode. You can inspect global variables (of course, you tend not to have very many global variables in Node.js apps, which are inherently modular), call global functions (same), and more to the point interact with the current scope when paused on a breakpoint.

You can also run Node.js directly with a debugging flag that tells it to allow a debugger to attach to it. For instance:

 node --inspect-brk server.js 

...tells Node.js to run with debugging enabled. You'l see something like:

 Debugger listening on ws://127.0.0.1:9229/89eff679-76ac-4972-9bd9-3142214c0b1f
For help, see: https://nodejs.org/en/docs/inspector 

If you open a Chromium-based browser and go to the URL chrome://inspect, you'll see your target listed:

 Target (v16.13.2)    trace
index.js
file:///path/to/server.js
inspect 

...where inspect is a link. Click it, and devtools will open, showing your code and that the execution is stopped on an automatic breakpoint at the very beginning of the code. (You can use --inspect instead of --inspect-brk if you don't want to start out at a breakpoint.)


238 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry