1
4

2 回答 2

2

No, there is no way to give write permissions in its own directory to a globally-installed Node module.

Indeed, to allow for global install, i.e. to be able to write in /usr/local/lib, NPM has to be run as root through sudo. However, when doing so, NPM will downgrade its user to nobody:

As of version 0.3, it is recommended to run npm as root. This allows npm to change the user identifier to the nobody user prior to running any package build or test commands.

All package scripts are run as nobody, and therefore cannot override this setting.

It is a safety feature that also prevents any unauthorized post-install modifications to an installed module, making installed modules trustable.


You should probably try to find a default place for your log that makes sense in your business logic. Defining a user-overridable (through a CLI switch) global writable log such as ~/.yourTool/log would be nice, but Node does not expand ~, so finding a cross-platform global logging destination seems a bit difficult.

于 2012-07-10T10:06:31.507 回答
0

I would do like that:

  • Log in CWD as default
  • Log path can be given as argument (like go -l /path/to/log)
  • Error if log file not writable
于 2012-07-10T09:37:23.630 回答