I'm trying to figure out if its possible for a user running a node.js script from the shell to pause the script, enter some input like verbosity level and then have the script continue execution. Basically I want to change a variable name (verbosity) while the script is actually running. The only other idea I had was parse a config file every few seconds with setInterval and reload the execution parameters.
2 Answers
Use fs.watch() to detect config file changes http://nodejs.org/api/fs.html#fs_class_fs_fswatcher
example
// Require the file system
fs = require("fs");
// Watch the sim directory
fs.watch("text.txt", { persistent: true }, function (event, fileName) {
console.log("Event: " + event);
console.log(fileName + "\n");
});
Comments
You can ask the user to write your variable name whenever you want showing a terminal question (like a prompt). stdio module helps you a lot doing this. For instance, when you need user input you can write the following:
var stdio = require('stdio');
stdio.question('What is your variable name?', function (err, varname) {
console.log('Your var name now is "%s"', varname);
// Do here whatever you want with varname
});
I hope this helps. I'm the stdio creator. :-)

(source: nodei.co)
1 Comment
korchix
+1 from me, because this package helps indeed. i used the function ask() to stop a running script, then continuing with the rest of it, after answering the question or just hitting "enter"
var limit = 100; orvar verbosity = 1;