Lodash in Shell

When both Node and Lodash are installed, they can be executed in shell scripts:

CHEESE="Camembert of Goat"
CAMEL_CHEESE=$(node -p -e "require('lodash').camelCase('${CHEESE}')")
KEBAB_CHEESE=$(node -p -e "require('lodash').kebabCase('${CHEESE}')")
echo $CAMEL_CHEESE # camembertOfGoat
echo $KEBAB_CHEESE # camembert-of-goat
Continue reading “Lodash in Shell”

Shell commands with Node

Running CLI Node scripts, capture the return value of a shell command:

const execSync = require('child_process').execSync;
const nodeVer = execSync('node -v', { encoding: 'utf8' });

Shell command reports in the CLI:

const execSync = require('child_process').execSync;
execSync('npm -g ls', { stdio: 'inherit' });