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 -v
This 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
.npmrc
to 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
.npmrc
file:arduinonpm config edit
- This will open the
.npmrc
file in your default text editor. - Add the following line to the file, replacing
your-username
with your actual Windows username:makefileCopy codeprefix=C:\Users\your-username\AppData\Roaming\npm
This 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 -y
This command initializes a new npm project by creating apackage.json
file 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.