What is equivalent to Perl inverse in Node.js?

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?

+4
source share
1 answer

Try to use . execSync with explicit encoding .. In shortest form (with space),

 var date = require('child_process').execSync('date', {encoding: 'utf8'} ) console.log(date); 
+4
source

All Articles