This is a class project, the teacher will accept only one (.js) file as the submit. In the project, I will need to read command from the console and react to it. Is that possible in js? I have tried event, however it seems like must base on html components.
            Asked
            
        
        
            Active
            
        
            Viewed 129 times
        
    1
            
            
        - 
                    Sure. You have to run JS on the console and read the standard input. The Node docs cover most of that, I believe. – ssube Sep 14 '16 at 17:39
- 
                    2So this is talking about something he can run the browser? Or is this something that can be run with Node? – arjabbar Sep 14 '16 at 17:40
- 
                    So I need to use Node.js is that right? – Hanrun Li Sep 14 '16 at 17:42
- 
                    On Windows the Scripting Host can do this, E.g. http://stackoverflow.com/questions/4441003/how-can-i-write-a-simple-jscript-input-output-program – Alex K. Sep 14 '16 at 17:44
1 Answers
0
            
            
        The read input from the command line, the prompt module of nodejs is nice :
var prompt = require('prompt')
process.on('uncaughtException', function (err) {
    log.error(err.stack)
    process.exit(1)
})
prompt.message = "> ".green;
prompt.delimiter = "";
var properties = [{
    name: 'login',
    message: 'login: '.white
}];
function onErr(err) {
    console.log(err);
    return 1;
}
function start () {
    prompt.start();
    prompt.get(properties, function (err, input) {
        if (err) {
            return onErr(err);
        }
        console.log("hello",input.login)
    });
}
start()
 
    
    
        Flint
        
- 1,651
- 1
- 19
- 29
- 
                    Thank you for the replay, since JS is really not suitable for such a mission We decided to use Java. – Hanrun Li Sep 14 '16 at 19:47
 
    