To set up npm (Node Package Manager) on Windows, you can follow these steps:
- Install Node.js: npm comes bundled with Node.js, so the first step is to install Node.js on your Windows machine. You can download the Node.js installer from the official website (https://nodejs.org) and run it. Choose the appropriate installer based on your system architecture (32-bit or 64-bit). The installer will guide you through the installation process.
- Verify the installation: After the installation is complete, open a command prompt or PowerShell window and type the following command to verify that Node.js and npm are installed:
node -v npm -vThis will display the installed versions of Node.js and npm. If you see the version numbers, it means the installation was successful.
- Set up npm: npm uses a configuration file called
.npmrcto manage its settings. By default, npm stores its global packages in a directory within your user profile. To configure npm, follow these steps:
- Open a command prompt or PowerShell window.
- Type the following command to create an
npm config edit
- This will open the
.npmrcfile in your default text editor.
- Add the following line to the file, replacing
your-usernamewith your actual Windows username:makefileCopy code
prefix=C:\Users\your-username\AppData\Roaming\npmThis sets the installation directory for global packages.
- Save the changes and close the file.
- Test npm: To test if npm is working correctly, open a new command prompt or PowerShell window and run the following command:csharpCopy code
npm init -yThis command initializes a new npm project by creating a
package.jsonfile with default settings. If the command executes without any errors, npm is set up properly.
You have successfully set up npm on your Windows machine. You can now use npm to install and manage packages for your Node.js projects.