2

log(`${chalk.magenta(' LAUNCH_COMMAND')} ${chalk.green('npm run: ')} ${chalk.red('${LAUNCH_COMMAND}')}` );

Here is the problem part: ${chalk.red('${LAUNCH_COMMAND}')}

LAUNCH_COMMAND is either 'production' or 'development'. However it's inside of another ${}.

enter image description here

Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
  • You absolutely should not [nest template strings](https://stackoverflow.com/q/36028061/1048572) if you want to keep your own sanity, and the code's readability. – Bergi Jul 14 '17 at 18:59

2 Answers2

3

Demo

Just use the Variable name for nested Variable in Template String literal

`${chalk.red(LAUNCH_COMMAND)}` // for nested sting literal just use the variable name 

const LAUNCH_COMMAND = 'hi';
console.log(`${chalk.magenta('  LAUNCH_COMMAND')} ${chalk.green('npm run: ')} ${chalk.red(LAUNCH_COMMAND)}` );

enter image description here

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
-1

You don't wrap variables within string literals with quotes.

log(`${chalk.magenta(  LAUNCH_COMMAND)} ${chalk.green(npm run: )} ${chalk.red(LAUNCH_COMMAND})` ); 

^ Should hypothetically work though I'm not clear on the context behind why you're writing a string like this. I'm assuming it's some kind of dynamic output.

var b = "Cats"
var c = "Dogs"

function concat(one, two) {

  return `${one} and ${two}`;

}

function compare(one, two) {

  var ans = one == two ? 'Are the same' : 'Are not the same';
  return ans;

}

console.log(`${concat(b, c)} - ${compare(b, c)}`);
trevdev
  • 241
  • 2
  • 12