Skip to content

General Stuff

Required Function Parameters

One way to deal with required function parameters in JavaScript - CSS-tricks.com Code Snippets

isRequired (general.js line 4)

Example isRequired usage

const logName = (name = isRequired("Name")) => console.log(name);

logName();

Example isRequired output

file:///home/mike/GitHub/personal/work-life/present/functions/General.js:6
  throw new Error(`${param} is required!`);
        ^

Error: Name is required!

Terminal commands with Node.js

I needed a way to run a terminal command in Node and wait for the results. This leads me to Node's Child process.

execPromise (general.js line 10)

Example execPromise usage

const whoAmI = (command) =>
  execPromise(command).then((response) => console.log(response));

whoAmI("whoami");

Example execPromise output

mike