简体   繁体   中英

node.js attach REPL to script

How do I start a node.js script and still be able to execute commands into the terminal ? I am looking for a node.js REPL that is also there for my custom script, so that I can inspect/log the state of my program for instance.

This is something similar to this JVM question , but for node.js.

I have tried node -i server.js without results. Do I need to have custom code in my script or is it feasible without that ? I saw this post , but it requires custom code, which I'd like to avoid.

Also, bonus points for reattaching a node script launched by an init script (I can see it in the process list : node -i server.js ).

You can start a repl loop from within your program

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

Does the other way round work for you?

Start the REPL and then load the script and then execute your commands. Use load to load your script.

Inside REPL, try

.load server.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM