'why does running `which` in a node child process result in different results?

when running the which command in terminal (for example, which yarn), I get a different result from when I'm running a node script (from the same location) which calls execSync('which yarn')

can someone explain why?

tldr;

// in terminal
which yarn
// results in 
/Users/xxx/.nvm/versions/node/v17.1.0/bin/yarn

// in node
execSync('which yarn')
// results in
/var/folders/0j/xxx/T/yarn--xxx/yarn


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source