Brew cannot run postinstall after upgrade to node

I just upgrade to the latest node and I saw that it wasn’t able to run brew postinstall node so it asked me to re-run it.

Here’s the output from brew doctor:

brew doctor
Your system is ready to brew.

Here’s the output from debugging postinstall:

brew postinstall node -d
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node.rb
==> Postinstalling node
/usr/local/Homebrew/Library/Homebrew/postinstall.rb (Formulary::FromPathLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node.rb
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`
==> An exception occurred within a child process:
  Errno::EACCES: Permission denied @ dir_s_mkdir - /usr/local/lib/node_modules/npm/node_modules/is-symbol

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1367:in `mkdir'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1367:in `copy'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:473:in `block in copy_entry'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1499:in `wrap_traverse'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1502:in `block in wrap_traverse'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1501:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1501:in `wrap_traverse'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1502:in `block in wrap_traverse'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1501:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1501:in `wrap_traverse'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:470:in `copy_entry'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:445:in `block in cp_r'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1572:in `block in fu_each_src_dest'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1586:in `fu_each_src_dest0'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1570:in `fu_each_src_dest'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:444:in `cp_r'
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node.rb:59:in `post_install'
/usr/local/Homebrew/Library/Homebrew/formula.rb:1009:in `block (2 levels) in run_post_install'
/usr/local/Homebrew/Library/Homebrew/formula.rb:866:in `with_logging'
/usr/local/Homebrew/Library/Homebrew/formula.rb:1008:in `block in run_post_install'
/usr/local/Homebrew/Library/Homebrew/utils.rb:478:in `with_env'
/usr/local/Homebrew/Library/Homebrew/formula.rb:1000:in `run_post_install'
/usr/local/Homebrew/Library/Homebrew/postinstall.rb:18:in `<main>'

I was able to resolve the issue by runnning sudo chown -R on the following:

/usr/local/lib/node_modules/npm/node_modules
/usr/local/lib/node_modules/npm/.npmrc
/usr/local/lib/node_modules/npm/