What is npm?
Overview
npm (Node Package Manager) is the default package manager for Node.js. It allows developers to install, share, and manage dependencies for their projects easily. With npm, you can install libraries, frameworks, and tools that help streamline your development process.
Installing npm
npm comes bundled with Node.js, so if you have Node.js installed, you already have npm available. You can verify your npm installation by running the following command in your terminal:
# Check npm version
npm -v
Common npm Commands
Here are some commonly used npm commands:
# Initialize a new package.json file
npm init
# Install a package
npm install <package-name>
# Uninstall a package
npm uninstall <package-name>
# Update a package
npm update <package-name>
# Install all dependencies listed in package.json
npm install
Creating a package.json File
The package.json
file is essential for any Node.js project. It contains metadata about your project and a list of dependencies. You can create one using:
# Create a package.json file with default values
npm init -y