Melbourne2991
Melbourne2991

Reputation: 11797

weird exec issue - stdout not showing - callback not working

The odd thing is this same code has worked previously. It seems that when I run the below now, I get no callback. None of the console logs work. However if I run "ls" instead of mongo for example it works fine, similarly if I write something like mongod -gfsssl (which should show an error) I do indeed get an error. Also if I run the same command as below in my terminal, it runs fine.

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

exec('mongod --dbpath="./data"', function(error, stdout, stderr) {
    console.log(stderr);
    console.log(error);
    console.log(stdout);

    nodemon({
        script: 'app/server.js',
        ext: 'js'
    });

    nodemon.on('start', function () {
        console.log('App has started');
    }).on('quit', function () {
        console.log('App has quit');
    }).on('restart', function (files) {
        console.log('App restarted due to: ', files);
    });
});

Upvotes: 0

Views: 209

Answers (1)

mscdex
mscdex

Reputation: 106698

Are you sure that mongod puts itself in the background after executing that command? It sounds like it's running in the foreground, causing the process to never exit (which is why your callback is never called).

Upvotes: 1

Related Questions