'Configure Yarn to puts .yarn and node_modules directories outside current directory

I'm wondering if there's a way to configure my node directory so Yarn puts its .yarn and node_modules directories outside of the current directory? That is, if my code is in /dir/dir/code, I'd like to have the .yarn files at /yarn , rather than /dir/dir/code/.yarn. Thanks!



Sources

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

Source: Stack Overflow

Solution Source