Files
30-seconds-of-code/snippets/isNode.md
Isabelle Viktoria Maciohsek caa67e2a49 Update snippet descriptions
2020-10-20 23:02:01 +03:00

503 B

title, tags
title tags
isNode node,browser,intermediate

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 is defined and process.versions, process.versions.node are not null.
const isNode = () =>
  typeof process !== 'undefined' &&
  process.versions !== null &&
  process.versions.node !== null;
isNode(); // true (Node)
isNode(); // false (browser)