0

I have set up a command line node module and when I run it one of the tasks is to start up the server and log to the console. However I find that although it starts up my server fine, it does not send the output to the console.

#! /usr/bin/env node

var userArgs = process.argv.slice(2);
var searchPattern = userArgs[0];

if(userArgs[0] === "start"){

    var exec = require('child_process').exec;

    exec('node ./server.js', 
        function(err, stdout, stderr) {
            console.log('stdout: ', stdout);
            console.log('stderr: ', stderr);
            if (error !== null) {
                console.log('exec error: ', error);
            }
        }
    );
}

So if I npm link my module then run mymodule start it starts the server fine but as I mentioned no output to the console.

Whereas if I run simply node server.js I get the output which is server listening on http://localhost:5000.

1 Answer 1

1

From the documentation, regarding the callback you are passing to 'exec'

'callback' - Function called with the output when process terminates

From what I understand, the process has to be terminated before you see 'stdout:' and 'stderr:' (you would have to stop the node process).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.