I'm really satisfied of using https://github.com/ohmyzsh/ohmyzsh.

Since I'm working with different node.js projects, they may use different node versions, and keeping track of node version in console would be really handy.

I've edited the default oh-my-zsh theme:

robbyrussell.zsh-theme

So, we'd like to show node version only in javascript projects. So we can check this by checking presence of package.json in current workdir.

ls | grep package.json

also we have to check if the node is installed

which node

So at the end I've came up with the function:

function node_prompt_version {
	if ls | grep package.json &> /dev/null; then
		if which node &> /dev/null; then
			echo $(node -v)
		fi
	fi
}

And as the final result adding it to the theme:

function node_prompt_version {
	if ls | grep package.json &> /dev/null; then
		if which node &> /dev/null; then
			echo "%{$fg_bold[blue]%}node:(%{$fg[red]%}$(node -v)%{$fg[blue]%})"
		fi
	fi
}

PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(node_prompt_version) $(git_prompt_info)'

ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"