Environment is Node.js

JavaScript, Node · Apr 2, 2021

Determines if the current runtime environment is Node.js.

  • Use the process global object that provides information about the current Node.js process.
  • Check if process, process.versions and process.versions.node are defined.
const isNode = () =>
  typeof process !== 'undefined' &&
  !!process.versions &&
isNode(); // true (Node)
isNode(); // false (browser)

More like this

  • Environment is browser

    Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.

    JavaScript, Browser · Oct 20, 2020

  • Calculate SHA-256 hash (Node.js)

    Creates a hash for a value using the SHA-256 algorithm. Returns a promise.

    JavaScript, Node · Oct 13, 2021

  • Stream is duplex

    Checks if the given argument is a duplex (readable and writable) stream.

    JavaScript, Node · Oct 20, 2020