As mentioned in a more recent answer, the preferred way is now simply:
const homedir = require('os').homedir();
[Original Answer]: Why not use the USERPROFILE
environment variable on win32?
function getUserHome() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}