npm always using home directory as current working directory
node.js, npm, powershell
Solution
Turns out I had a `cd C:\Users\<myusername>` command in `HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun` in the registry. Meaning that this command was executed any time `CMD.EXE` started.
No idea how that got in there, I might have added it myself at some point.
Anyway, if someone experiences differences between the current working directory when executing a script and when running the same command manually in an open command prompt, `HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun` and `HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun`are good places to check.
Problem
npm insists on using my home directory as the current working directory, no matter which directory I am executing commands from. Happens with both cmd and Powershell, I've tried removing and reinstalling node, both using the installer on nodejs.org, and via Chocolatey with the same result. If I navigate to e.g. `C:\test` and run `npm init`, the wizard places the resulting `package.json` file in my home folder. If I run `npm install <package>` from any folder, the package is installed to `C:\Users\myusername\node_modules` Trying to install a package globally also fails, with this ``` npm ERR! System Windows_NT 6.1.7601 npm ERR! command "C:\\ProgramData\\chocolatey\\lib\\nodejs.commandline.0.10.33\\tools\\node.exe" "C:\\ProgramData\\chocolatey\\lib\\npm.1.4.9\\tools\\node_modules\\npm\\bin\\npm-cli.js" "install" "gulp" "-g" npm ERR! cwd C:\Users\<myusername> ``` If I navigate to a folder, start the node REPL and run `process.cwd()` the directory I started node from is returned, so the issue seems to be limited to npm. Running `npm get` gives this result: ``` C:\test> npm get ; cli configs registry = "https://registry.npmjs.org/" user-agent = "npm/1.4.9 node/v0.10.33 win32 x64" ; node bin location = C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.33\tools\node.exe ; cwd = C:\Users\<myusername> ; HOME = C:\Users\<myusername> ; 'npm config ls -l' to show all defaults. ``` I've searched quite a bit for a solution, and have found some similar issues, but none that solved my problem. I know that npm walks up the directory tree to look for a node_modules folder, but this happens in folders outside my home directory as well. Any tips on what I try to resolve this?