0

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.

4
  • Change a variable name or a variable value? Commented May 23, 2014 at 5:36
  • variable value of verbosity as I see it. Commented May 23, 2014 at 5:38
  • The value of something like var limit = 100; or var verbosity = 1; Commented May 24, 2014 at 6:15
  • No, that would require a Turing machine. Commented Aug 15, 2014 at 2:44

2 Answers 2

1

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");
});
Sign up to request clarification or add additional context in comments.

Comments

1

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. :-)

NPM
(source: nodei.co)

1 Comment

+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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.