Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
npm (Node Package Manager) and Yarn are package managers that help you install, manage, and share JavaScript libraries. They handle dependencies, versioning, and make it easy to use thousands of open-source packages in your projects.
One command to add libraries to your project
Track versions and update packages easily
Publish your own packages to npm registry
Create new project
Create new project
Install a package
Install a package
Install dev dependency
Install dev dependency
Remove a package
Remove a package
Update all packages
Update all packages
# Create a new project
npm init -y
# Install React (production dependency)
npm install react react-dom
# Install Webpack (development dependency)
npm install --save-dev webpack webpack-cli
# Install globally (available everywhere)
npm install -g create-react-app
# Install specific version
npm install lodash@4.17.21
# Install from GitHub
npm install user/repo
# Check installed packages
npm list
# Check outdated packages
npm outdated# package.json scripts section
{
"scripts": {
"start": "node server.js",
"dev": "webpack serve --mode development",
"build": "webpack --mode production",
"test": "jest",
"lint": "eslint src/"
}
}
# Run scripts with npm
npm start # Runs "node server.js"
npm run dev # Runs webpack dev server
npm run build # Production build
npm test # Run tests
# Run scripts with Yarn
yarn start
yarn dev
yarn build
yarn testnpm and Yarn manage dependencies
Make development easier
npm install / yarn add
Install packages in seconds
Ensure consistent installs
Commit to version control
Automate common tasks
Define in package.json