Nvm install shows "MODULE_NOT_FOUND" after npm init

I installed Node Version Manager (nvm) to use the latest version of Node (13.6.0). After running the command nvm use 13.6.0, I was able to use the latest version of Node. However, when I tried running npm init, I encountered the following error:

  throw err;

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:973:15)
    at Function.Module._load (internal/modules/cjs/loader.js:855:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  requireStack: []

To solve this issue, I added the path to each version of Node to the system variables. This was done on a Windows 10 (x64) machine.

Answer: To solve the issue, you need to add the path to the npm executable to the system environment variables. The path to the npm executable can be found by running the command nvm which current. Once you have the path, follow the steps below:

  1. Open the Start menu and search for “Environment Variables”
  2. Click on “Edit the system environment variables”
  3. Click on the “Environment Variables” button
  4. Under “System Variables”, scroll down and click on “Path” then click “Edit”
  5. Click “New” and paste the path to the npm executable (e.g. C:\Users{your_username}\AppData\Roaming\nvm\current\bin)
  6. Click “OK” on all open windows to save the changes
  7. Open a new command prompt and try running npm init again.