Npm installs packages in an unexpected local directory

Using npm add socketLib, my package installs in ~/app_modules instead of ./modules. npm locate shows the path, and npm setcfg path ./modules doesn’t fix it. How can I revert?

The issue might be related to an incorrect configuration for the installation directory. In my experience settings such as the prefix can shift where npm places packages. Verifying the current configuration with npm config get prefix helped me identify a misconfigured path. Adjusting it to an absolute path and making sure no environment variables override it resolved the problem. It may be beneficial to review your .npmrc file for unexpected configuration lines. A clean configuration often prevents these issues from arising unexpectedly in the future.