You can check if a string is empty using -z
:
node_process_id=$(pidof node)
if [[ -z $node_process_id ]]; then
node server.js &
fi
pidof
returns nothing if no matching processes are found, so node_process_id
would be set to an empty string.