From 805c6bd36c7529496a12b6c282f7e002b27aaea2 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan <55143799+dephraiim@users.noreply.github.com> Date: Mon, 12 Oct 2020 17:01:21 +0000 Subject: [PATCH] Add isNode, randomIpAddress and isRegularExpression (#1526) * add isNode() Co-authored-by: Angelos Chalaris --- snippets/isNode.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 snippets/isNode.md diff --git a/snippets/isNode.md b/snippets/isNode.md new file mode 100644 index 000000000..c310a43fa --- /dev/null +++ b/snippets/isNode.md @@ -0,0 +1,21 @@ +--- +title: isNode +tags: node,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`. + +```js +const isNode = () => + typeof process !== 'undefined' && + process.versions !== null && + process.versions.node !== null; +``` + +```js +isNode(); // true (Node) +isNode(); // false (browser) +```