In Perl, you can do something like
perl -E'my $date = `date`; say $date'
This is a short way to run the command synchronously and set the variable to STDOUT. In Node, how can I quickly run a command to write stdout?
Try to use . execSync with explicit encoding .. In shortest form (with space),
var date = require('child_process').execSync('date', {encoding: 'utf8'} ) console.log(date);