2

I'm just starting with Node.js but I have experience with client-side JavaScript and PHP/Apache.

In your browser you can execute JS code from the developer console at any time. You can manipulate global vars and call global functions and methods. If I call console.log('Hello world!') from the browser's developer console, it will log the message to the console I'm using, just like in a script you write.

In Node.js when you call console.log('Hello world!') from within your "app", the result is logged as you'd expect, just like JS on the client-side. Can I do what I would do on the client-side?

My question is can I execute my own JS code from the command line like I would on the client-side, manipulating vars (such as the HTTP server, filesystem, etc.) and calling functions that are available in my app? I don't care why, I just want to know if I can do it.

Jared
  • 2,780
  • 4
  • 24
  • 38
  • @Juhana It's hardly a duplicate. I don't want to debug my apps nor do I want to use a browser. Thanks for the link though. – Jared May 26 '14 at 09:08
  • The duplicate tells how to do all the stuff you ask for. Read all the answers, not just the top voted one. – JJJ May 26 '14 at 09:09
  • Thanks for directing me to a specific answer. – Jared May 26 '14 at 09:12

1 Answers1

1

V8 comes with an extensive debugger which is accessible out-of-process via a simple TCP protocol. Node has a built-in client for this debugger. To use this, start Node with the debug argument; a prompt will appear:

Node's debugger client doesn't support the full range of commands, but simple step and inspection is possible. By putting the statement debugger; into the source code of your script, you will enable a breakpoint.

http://nodejs.org/api/debugger.html

Yes this is possible. You just need to write the statement debugger wherever you want your code to stop and you want to use the command line (and start node with the debug argument, eg: node debug app.js

Community
  • 1
  • 1
edi9999
  • 16,352
  • 11
  • 70
  • 121