title: Write file in home directory when running `npm install`
body: <p>When install a <code>foo</code> module, as developer, I want to write <code>~/.foo.json</code> file (where <code>~/</code> is the user's home directory).</p>
  
  <p>For this I did in <code>package.json</code>:</p>
  
  <pre><code>{
    ...
    "scripts": {
       "preinstall": "./installation/preinstall.js"
    },
    ...
  }
  </code></pre>
  
  <p>And in <code>/installation/preinstall.js</code> (that is executable), I have:</p>
  
  <pre><code>#!/usr/bin/env node
  
  // Dependencies
  var Fs = require("fs");
  
  function getUserHome() {
      return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
  }
  
  console.log("Creating configuration file ...")
  Fs.writeFileSync(getUserHome() + "/" + ".foo.json", JSON.stringify(
      require("./sample-config"), null, 4
  ));
  </code></pre>
  
  <p>When running <code>sudo npm install ...@... -g</code> I get the following output:</p>
  
  <pre><code>ionicabizau@laptop:~$ sudo npm install ...@...-alpha1 -g                           
  npm http GET https://registry.npmjs.org/...
  npm http 304 https://registry.npmjs.org/...
  
  &gt; ...@...-alpha1 preinstall /usr/lib/node_modules/...
  &gt; ./installation/preinstall.js
  
  Creating configuration file ...
  
  fs.js:432
    return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                   ^
  Error: EACCES, permission denied '/home/ionicabizau/.foo.json'
      at Object.fs.openSync (fs.js:432:18)
      at Object.fs.writeFileSync (fs.js:971:15)
      at Object.&lt;anonymous&gt; (/usr/lib/node_modules/.../installation/preinstall.js:11:4)
      at Module._compile (module.js:456:26)
      at Object.Module._extensions..js (module.js:474:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:312:12)
      at Function.Module.runMain (module.js:497:10)
      at startup (node.js:119:16)
      at node.js:906:3
  </code></pre>
  
  <p>Why <code>EACCESS</code> error, even if I run it with <code>sudo</code>?</p>
  
  <p>Running Ubuntu 14.04, if it's relevant.</p>