Extension Attribute for Determining if Node.js is Installed and Displaying the Version if So

john_sherrod
Contributor II

We had a need to do an inventory of which of our Macs has Node.js installed and to display the Node.js version. I wanted to share this in case it's helpful for anyone else. Basically it checks to see if /usr/local/bin/node is present and if so it runs a command to display the version number. Here's the script:

#!/bin/bash

# Tests to see if Node.js is installed. If it is, it outputs the version number. If it’s not, it states that Node.js is not installed.

if [ -f "/usr/local/bin/node" ]
then
    echo "<result>`node -v`</result>"
else
    echo "<result>Node.js is not installed</result>"
fi
1 REPLY 1

julienvs
New Contributor III

Thanks @john.sherrod , very useful!