node.js – "the npm configuration set prefix" fails on the user-owned directory in macOS Mojave

I'm installing the node on a clean macOS Mojave box using Homebrew. I'm trying to set the installation directory of npm in a directory belonging to the user; the dir tools already exists and belongs to the user:

The configuration set prefix npm - / Users / giorgio / tools / npm_global & # 39;

And that fails with this message. Does anyone know what's going on?

Error: EACCES: Permission Denied, mkdir & # 39; / tools & # 39;
TypeError: Unable to read property & # 39; loaded & # 39; undefined
at the output (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27)
at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:78:20
at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22)
at /usr/local/lib/node_modules/npm/lib/npm.js:263:24
at /usr/local/lib/node_modules/npm/lib/config/core.js:83:7
at Array.forEach ()
at /usr/local/lib/node_modules/npm/lib/config/core.js:82:13
at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:173:20)
/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98
var doExit = npm.config.loaded? npm.config.get (-ex exit): true
^

TypeError: Unable to read property & # 39; loaded & # 39; undefined
at the output (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27)
at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
at process.emit (events.js: 197: 13)
at process._fatalException (internal / process / execution.js: 123: 25)