NPM Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。
npm (Node Package Manager) is the default package manager for Node.js. It allows you to install, update, and manage packages (libraries or modules) for your Node.js applications.
Install Node.js from nodejs.org, which includes npm. After installation, you can check the installed version of npm using the following command:
npm --version
# or
npm -v
npm init # Interactive setup
# or
npm init -y # Creates a package.json with default values
npm install
# or
npm i
npm install <package-name> # Install and add to dependencies
npm install <package-name> --save-dev # Add to devDependencies
npm install <package-name> -D # Shorthand for --save-dev
npm install <package-name> -g # Install globally
npm install <package-name>@<version> # Install specific version
npm install <package-name>@latest # Install latest version
npm uninstall <package-name> # Uninstall package
npm uninstall <package-name> -g # Uninstall globally
npm rm <package-name> # Shorthand for uninstall
npm view <package-name> # View package details
npm view <package-name> versions # View all versions of a package
npm view <package-name> version # View the latest version of a package
npm view <package-name> description # View the description of a package
npm search <search-term> # Search for packages with similar terms
npm docs <package-name> # Open package documentation in the browser
npm home <package-name> # Open package homepage in the browser
npm repo <package-name> # Open package repository in the browser
npm outdated # Check for outdated packages
npm update <package-name> # Update a specific package
npm update # Update all packages
npm list # List installed packages in the current project
npm list -g # List globally installed packages
npm list --depth=0 # List top-level installed packages only
npm run <script-name> # Run a script defined in package.json
npm start # Run the 'start' script
npm test # Run the 'test' script
npm build # Run the 'build' script
npm cache verify # Verify the integrity of the npm cache
npm cache clean # Clear the npm cache
npm cache clean --force # Force clear the npm cache
npm config list # List all npm configuration settings
npm config set <key> <value> # Set a configuration value
npm config get <key> # Get the value of a configuration key
npm config delete <key> # Delete a configuration key
npm audit # Audit dependencies for vulnerabilities
npm audit fix # Fix vulnerabilities in dependencies
npm audit fix --force # Force fix vulnerabilities, may update major versions
npm login # Log in to your npm account (npmjs.com)
npm publish # Publish a package to the npm registry
npm version <new-version> # Bump the version of your package (e.g., patch, minor, major)
npm unpublish <package-name> # Unpublish a package (within 72 hours of publishing)
npm help # Get general help on npm
npm help <command> # Get help on a specific npm command
npm ci # Install dependencies from package-lock.json (clean install)
npm prune # Remove extraneous packages
npm dedupe # Reduce duplication in the node_modules folder
地址
Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)Level 2, 171 La Trobe St, Melbourne VIC 3000四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号Business Hub, 155 Waymouth St, Adelaide SA 5000Disclaimer
JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.
匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议
© 2017-2025 JR Academy Pty Ltd. All rights reserved.
ABN 26621887572