├── .gitattributes ├── .github └── funding.yml ├── .editorconfig ├── contributing.md ├── code-of-conduct.md ├── license └── readme.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: sindresorhus 2 | open_collective: sindresorhus 3 | patreon: sindresorhus 4 | custom: https://sindresorhus.com/donate 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | Please note that this project is released with a [Contributor Code of Conduct](code-of-conduct.md). By participating in this project you agree to abide by its terms. 4 | 5 | --- 6 | 7 | Ensure your pull request adheres to the following guidelines: 8 | 9 | - **The submitted project should be more than 30 days old and the repo should have at least 40 stars.** 10 | - Don't open a Draft / WIP pull request while you work on the guidelines. A pull request should be 100% ready and should adhere to all the guidelines when you open it. 11 | - Search previous suggestions before making a new one, as yours may be a duplicate. 12 | - If you submit a project that is similar to an existing project in the list, argue how it's better. 13 | - You should of course have read/used the thing you're submitting. 14 | - Make an individual pull request for each suggestion. 15 | - Suggested packages should be tested and documented. 16 | - Use the following format: `[name](link) - Description.` 17 | - Keep descriptions short and simple, but descriptive. 18 | - Start the description with a capital and end with a full stop/period. 19 | - Check your spelling and grammar. 20 | - Make sure your text editor is set to remove trailing whitespace. 21 | - Link additions should be added to the bottom of the relevant section. 22 | - New categories or improvements to the existing categorization are welcome. 23 | - Pull requests should have a useful title and include a link to the package and why it should be included. 24 | 25 | Thank you for your suggestion! 26 | 27 | ### Updating your PR 28 | 29 | A lot of times, making a PR adhere to the standards above can be difficult. If the maintainers notice anything that we'd like changed, we'll ask you to edit your PR before we merge it. There's no need to open a new PR, just edit the existing one. If you're not sure how to do that, [here is a guide](https://github.com/RichardLitt/docs/blob/master/amending-a-commit-guide.md) on the different ways you can update your PR so that we can merge it. 30 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at sindresorhus@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Awesome npm [![Awesome](https://awesome.re/badge.svg)](https://awesome.re) [npm](https://www.npmjs.com) 2 | 3 | > Awesome [npm](https://www.npmjs.com) resources and tips 4 | 5 | [npm](https://en.wikipedia.org/wiki/Npm_(software)) is a package manager for the JavaScript programming language and comes bundled in the [Node.js](https://en.wikipedia.org/wiki/Node.js) runtime. 6 | 7 | *Please read the [contribution guidelines](contributing.md) before contributing.* 8 | 9 | ## Contents 10 | 11 | - [Articles](#articles) 12 | - [Tools](#tools) 13 | - [Packages](#packages) 14 | - [Clients](#clients) 15 | - [Tips](#tips) 16 | - [FAQ](#faq) 17 | - [Community](#community) 18 | - [Documentation](#documentation) 19 | - [Support](#support) 20 | - [Related](#related) 21 | 22 | ## Articles 23 | 24 | - [Small focused modules](https://github.com/sindresorhus/ama/issues/10#issuecomment-117766328) 25 | - [Unix philosophy and Node.js](http://blog.izs.me/post/48281998870/unix-philosophy-and-nodejs) - Write programs that do one thing and do it well. 26 | - [Writing small modules](https://web.archive.org/web/20180302125059/https://substack.net/how_I_write_modules) 27 | - [Semver: A Primer](https://nodesource.com/blog/semver-a-primer/) *(Must read!)* 28 | - [Semver: Tilde and Caret](https://nodesource.com/blog/semver-tilde-and-caret/) 29 | - [Offline installation of npm packages](https://addyosmani.com/blog/using-npm-offline/) 30 | - [Task automation with npm run](https://web.archive.org/web/20180302164842/http://substack.net/task_automation_with_npm_run) 31 | - [How to use npm as a build tool](https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/) 32 | - [Install npm packages globally without sudo on macOS and Linux](https://github.com/sindresorhus/guides/blob/main/npm-global-without-sudo.md) 33 | - [Optimizing the footprint of an npm package](https://medium.com/@goldglovecb/npm-needs-a-personal-trainer-537e0f8859c6) 34 | - [The Art of Node](https://github.com/maxogden/art-of-node#modules) - An introduction to Node.js and client-side development with npm. 35 | - [Why npm scripts?](https://css-tricks.com/why-npm-scripts/) - An introduction to npm scripts with common packages and scripts, as well as a boilerplate project. 36 | 37 | ## Tools 38 | 39 | ### Web 40 | 41 | - [npms](https://npms.io) - Superb package search with deep analysis of package quality using a [myriad of metrics](https://npms.io/about). 42 | - [npm-introspect](http://npm-introspect.z3d.tech) - A npms-based utility for visually exploring the quality of package dependencies. 43 | - [node-modules](http://node-modules.com) - Personalized package search based on your GitHub social graph. 44 | - [NodeICO](https://nodei.co/) - Package badges. 45 | - [Libraries.io](https://libraries.io/npm) - Package discovery. 46 | - [npm-stat](http://npm-stat.com) - Statistics charts for packages. 47 | - [npmgraph](http://npm.anvaka.com) - Visualization of dependencies. 48 | - [npm trends](http://www.npmtrends.com) - Compare package download counts over time. 49 | - [npm-compare](https://npmcompare.com) - Easily search and compare packages. 50 | - [npm-top](https://gist.github.com/bcoe/dcc961b869bbf6685002) - npm users by downloads. 51 | - [npm semver calculator](http://semver.npmjs.com) - Visually explore what versions of a package a semver range matches. 52 | - [ghub.io](https://ghub.io) - Redirects to the GitHub repo of an npm package. 53 | - [npm addict](https://npmaddict.com) - Your daily injection of npm packages. 54 | - [moiva](https://moiva.io) - Discover and compare packages. 55 | - [Openbase](https://openbase.com) - Compare open-source packages with powerful metrics and user reviews. 56 | - [Codelib.club](https://codelib.club) - Search and discover open-source apps by dependencies. 57 | 58 | ### Browser extensions 59 | 60 | - [Octo-Linker](https://chrome.google.com/webstore/detail/octo-linker/jlmafbaeoofdegohdhinkhilhclaklkp) - Chrome extension to navigate across npm packages on GitHub with ease. 61 | - [npm-hub](https://chrome.google.com/webstore/detail/npm-hub/kbbbjimdjbjclaebffknlabpogocablj) - Chrome extension to explore npm dependencies on GitHub repos. 62 | - [github-npm-stats](https://chrome.google.com/webstore/detail/github-npm-stats/oomfflokggoffaiagenekchfnpighcef) - View npm download stats on GitHub. 63 | - [npm-search-update](https://chrome.google.com/webstore/detail/npm-search-update/kagpoplamlmaonpddimnnigiojimihnh) - Chrome extension to quickly search for dependencies and monitor changes from the npm registry. 64 | 65 | ### CLI 66 | 67 | - [zsh-better-npm-completion](https://github.com/lukechilds/zsh-better-npm-completion) - Better ZSH completion for npm. 68 | - [npkill](https://github.com/voidcosmos/npkill) - Easily find and remove old and heavy node_modules folders. 69 | 70 | ## Packages 71 | 72 | ### Publishing 73 | 74 | - [np](https://github.com/sindresorhus/np) - A better `npm publish`. 75 | - [publish-please](https://github.com/inikulin/publish-please) - Publish packages safely and gracefully. 76 | - [npm-release](https://github.com/phuu/npm-release) - Making releasing to npm so easy a kitten could probably do it™. 77 | - [pkgfiles](https://github.com/timoxley/pkgfiles) - List all files which would be published in a package. 78 | - [release-it](https://github.com/webpro/release-it) - Automate releases for Git repositories and/or npm packages. Changelog generation, GitHub/GitLab releases, etc. 79 | - [semantic-release](https://github.com/semantic-release/semantic-release) - Fully automated package publishing. 80 | 81 | ### Registry 82 | 83 | - [npm-name](https://github.com/sindresorhus/npm-name-cli) - Check whether a package name is available on npm. 84 | - [package-json](https://github.com/sindresorhus/package-json) - Get the package.json of a package from the npm registry. 85 | - [latest-version](https://github.com/sindresorhus/latest-version-cli) - Get the latest version of an npm package. 86 | - [npm-keyword](https://github.com/sindresorhus/npm-keyword) - Get a list of npm packages with a certain keyword. 87 | - [npm-user](https://github.com/sindresorhus/npm-user) - Get user info of an npm user. 88 | - [npm-email](https://github.com/sindresorhus/npm-email) - Get the email of an npm user. 89 | - [npm-user-packages](https://github.com/kevva/npm-user-packages-cli) - Get packages by an npm user. 90 | - [dpn](https://github.com/gillstrom/dpn) - Get the dependents of a user's npm packages. 91 | - [npm-stats](https://github.com/hughsk/npm-stats) - Get data from an npm registry. 92 | - [npm-cli-login](https://github.com/postmanlabs/npm-cli-login) - Log in to npm. 93 | - [nrm](https://github.com/Pana/nrm) - Registry manager. 94 | - [npm-register](https://github.com/dickeyxxx/npm-register) - Easy to set up and maintain npm registry and proxy. 95 | - [verdaccio](https://github.com/verdaccio/verdaccio) - Lightweight private npm proxy registry. 96 | - [cloudsmith](https://cloudsmith.io/l/npm-registry/) - A fully managed package management SaaS with support for public and private npm registries (and many others). 97 | 98 | ### Other 99 | 100 | - [npm-home](https://github.com/sindresorhus/npm-home) - Open the npm page of a package. 101 | - [gh-home](https://github.com/sindresorhus/gh-home) - Open the GitHub page of a package. 102 | - [david](https://github.com/alanshaw/david) - Check if your package dependencies are out of date. 103 | - [npm-check](https://github.com/dylang/npm-check) - Check for outdated, incorrect, and unused dependencies, as well as interactive update. 104 | - [npm-upgrade](https://github.com/th0r/npm-upgrade) - Update outdated npm dependencies interactively. 105 | - [npm-shrinkwrap](https://github.com/uber/npm-shrinkwrap) - A consistent shrinkwrap tool. 106 | - [npm-windows-upgrade](https://github.com/felixrieseberg/npm-windows-upgrade) - Upgrade npm on Windows. 107 | - [generator-nm](https://github.com/sindresorhus/generator-nm) - Scaffold out an npm package. 108 | - [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file. 109 | - [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) - Read the closest package.json file. 110 | - [normalize-package-data](https://github.com/npm/normalize-package-data) - Normalize package metadata. 111 | - [pkg-conf](https://github.com/sindresorhus/pkg-conf) - Get namespaced config from the closest package.json. 112 | - [npm-run-path](https://github.com/sindresorhus/npm-run-path) - Run locally installed binaries in the terminal by name like with global ones. 113 | - [local-npm](https://github.com/nolanlawson/local-npm) - Use npm [offline](https://addyosmani.com/blog/using-npm-offline/). 114 | - [npe](https://github.com/zeke/npe) - CLI for inspecting and editing properties in package.json. 115 | - [engine-deps](https://github.com/samccone/engine-deps) - Manage Node.js version specific dependencies with ease. 116 | - [enpeem-search](https://github.com/amovah/enpeem-search) - Search packages by scraping the npm web search. 117 | - [npm-issues](https://github.com/seanzarrin/npm-issues) - Search known issues of all your packages at once. 118 | - [john](https://github.com/davej/john) - Make npm3's flat dependencies easier to find and sort. 119 | - [ntl](https://github.com/ruyadorno/ntl) - Interactive CLI menu to list & run npm tasks. 120 | - [decheck](https://github.com/egoist/decheck) - Explore dependencies of npm packages in the command-line. 121 | - [shrinkpack](https://github.com/JamieMason/shrinkpack) - Lock down your dependencies and install offline. 122 | - [redrun](https://github.com/coderaiser/redrun) - Expand scripts from package.json to improve execution speed. 123 | - [package-size](https://github.com/egoist/package-size) - Get the bundle size of an npm package. 124 | - [synp](https://github.com/imsnif/synp) - Convert yarn.lock to package-lock.json and vice versa. 125 | - [npm-run-all](https://github.com/mysticatea/npm-run-all) - CLI tool to run multiple npm-scripts in parallel or serial. 126 | - [onchange](https://github.com/Qard/onchange) - Watch files and folders and run a command when something changed. 127 | - [cli-error-notifier](https://github.com/micromata/cli-error-notifier) - Sends native desktop notifications when npm scripts fail. 128 | - [luna](https://github.com/rvpanoz/luna) - App to manage npm dependencies. 129 | - [emma-cli](https://github.com/maticzav/emma-cli) - Interactive CLI package search utility. 130 | - [lockfile-lint](https://github.com/lirantal/lockfile-lint) - Lint lockfiles for improved security and trust policies to mitigate malicious package injection and insecure lockfile resources. 131 | 132 | ## Clients 133 | 134 | - [yarn](https://github.com/yarnpkg/yarn) - Fast, reliable, and secure dependency management. 135 | - [npm](https://github.com/npm/cli) - The official client. 136 | - [pnpm](https://github.com/pnpm/pnpm) - Fast, disk space efficient package manager. 137 | 138 | ## Tips 139 | 140 | ### Update to the latest npm version 141 | 142 | ``` 143 | $ npm install --global npm 144 | ``` 145 | 146 | *[Windows users, read more.](https://github.com/felixrieseberg/npm-windows-upgrade)* 147 | 148 | ### Command aliases 149 | 150 | - `npm i ` → `npm install` 151 | - `npm i -D` → `npm install --save-dev` 152 | - `npm t` → `npm test` 153 | - `npm it` → `npm install && npm test` 154 | - `npm r` → `npm uninstall` 155 | - `npm un` → `npm uninstall` 156 | - `npm up` → `npm update` 157 | 158 | ### Shell aliases 159 | 160 | Speed up your common npm tasks. 161 | 162 | In your `.zshrc`/`.bashrc`: 163 | 164 | ```sh 165 | alias ni='npm install' 166 | alias nid='npm install --save-dev' 167 | alias nig='npm install --global' 168 | alias nt='npm test' 169 | alias nit='npm install && npm test' 170 | alias nk='npm link' 171 | alias nr='npm run' 172 | alias ns='npm start' 173 | alias nf='npm cache clean && rm -rf node_modules && npm install' 174 | alias nlg='npm list --global --depth=0' 175 | ``` 176 | 177 | ### Don't add to package.json when installing 178 | 179 | By default npm adds packages you install to the `dependencies` field in package.json (since v5). You can prevent this by specifying the `--no-save` flag. You can add a package to `devDependencies` with `--save-dev`/`-D`: 180 | 181 | ``` 182 | $ npm install --save-dev ava 183 | ``` 184 | 185 | ### Run scripts 186 | 187 | You can easily [run scripts](https://docs.npmjs.com/cli/run-script) using npm by adding them to the `"scripts"` field in package.json and run them with `npm run `. Run `npm run` to see available scripts. Binaries of locally install packages are made available in the [PATH](https://en.wikipedia.org/wiki/PATH_(variable)), so you can run them by name. 188 | 189 | ```json 190 | { 191 | "name": "awesome-package", 192 | "scripts": { 193 | "cat": "cat-names" 194 | }, 195 | "dependencies": { 196 | "cat-names": "^1.0.0" 197 | } 198 | } 199 | ``` 200 | 201 | ``` 202 | $ npm run cat 203 | Max 204 | ``` 205 | 206 | All package.json properties are [exposed](https://docs.npmjs.com/misc/scripts#packagejson-vars) as environment variables: 207 | 208 | ```json 209 | { 210 | "name": "awesome-package", 211 | "scripts": { 212 | "name": "echo $npm_package_name" 213 | } 214 | } 215 | ``` 216 | 217 | ``` 218 | $ npm run name 219 | awesome-package 220 | ``` 221 | 222 | #### Passing options to commands 223 | 224 | You can pass options to the command you are using in your npm script by adding `-- --flag` like in the example below. The `--` [marks the end of options parsing](https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash), so `npm run` will just ignore it and pass it to the command. 225 | 226 | ```json 227 | { 228 | "name": "awesome-package", 229 | "scripts": { 230 | "xo": "xo", 231 | "xo:fix": "npm run xo -- --fix", 232 | } 233 | } 234 | ``` 235 | 236 | *Adding the `-- --fix ` option is like executing `xo --fix`*. 237 | 238 | #### Silent option 239 | 240 | `npm run` has a `--silent` option which is especially useful when combining npm scripts. 241 | 242 | Imagine you have a setup for linting your JavaScript files like the following: 243 | 244 | ```json 245 | { 246 | "name": "awesome-package", 247 | "scripts": { 248 | "xo": "xo", 249 | "xo:fix": "npm run xo --silent -- --fix", 250 | } 251 | } 252 | ``` 253 | 254 | *Using the `--silent` option reduces the output in the terminal. See [this comparison](https://twitter.com/mkuehnel/status/957965749473210369).* 255 | 256 | ### Lifecycle scripts 257 | 258 | npm comes with predefined [lifecyle scripts](https://docs.npmjs.com/misc/scripts) which are excuted under specific conditions if they are defined in your package.json. 259 | 260 | ```json 261 | { 262 | "name": "awesome-package", 263 | "scripts": { 264 | "prepublishOnly": "nsp check" 265 | }, 266 | "devDependencies": { 267 | "nsp": "^3.0.0" 268 | } 269 | } 270 | ``` 271 | 272 | This will be executed automatically before your npm package is published to the registry via `npm publish` to check for known vulnerabilties in your dependencies. 273 | 274 | *Note: **prepublishOnly** is available since npm v4.0.0. See [npm docs](https://docs.npmjs.com/misc/scripts#deprecation-note).* 275 | 276 | #### `npm start` and `npm test` 277 | 278 | `npm start` and `npm test` are also lifecycle scripts but are not executed automatically. 279 | 280 | ```json 281 | { 282 | "name": "awesome-package", 283 | "scripts": { 284 | "start": "node server.js", 285 | "test": "ava" 286 | }, 287 | "devDependencies": { 288 | "ava": "^1.0.0" 289 | } 290 | } 291 | ``` 292 | 293 | Therefore they can be executed simply with: 294 | 295 | ```console 296 | $ npm test 297 | $ npm start 298 | ``` 299 | 300 | #### `pre` and `post` scripts 301 | 302 | These are special lifecycle scripts which can be used to run scripts automatically in sequence. 303 | 304 | ```json 305 | { 306 | "name": "awesome-package", 307 | "scripts": { 308 | "pretest": "eslint .", 309 | "test": "ava" 310 | }, 311 | "devDependencies": { 312 | "eslint": "^4.19.0", 313 | "ava": "^1.0.0" 314 | } 315 | } 316 | ``` 317 | 318 | ```console 319 | $ npm test 320 | ``` 321 | 322 | This will lint your files before running your tests. The tests will not run if linting fails. Or more generally spoken: the following script won’t be executed if one of the scripts running in sequence exits with an exit code other than 0. 323 | 324 | *Note: `pre` and `post` scripts can also be used for your custom npm scripts. So `npm run foo` will also run `prefoo` and `postfoo` if defined.* 325 | 326 | ### Run script with `npx` 327 | 328 | `npm` [comes bundled](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) with `npx` (Since v5.2.0) — a tool to execute package binaries. Each command is executed either from the local `node_modules/.bin` directory, or from a central cache, installing any packages needed in order for `` to run. 329 | 330 | ```json 331 | { 332 | "name": "awesome-package", 333 | "dependencies": { 334 | "cat-names": "^1.0.0" 335 | } 336 | } 337 | ``` 338 | 339 | If the binary is already installed, it will be executed from `node_modules/.bin`. 340 | 341 | ``` 342 | $ npx cat-names 343 | Max 344 | ``` 345 | 346 | But if the binary is missing, it will be installed first. 347 | 348 | ``` 349 | $ npx dog-names 350 | npx: installed 46 in 3.136s 351 | Bentley 352 | ``` 353 | 354 | ### Run commands with different Node.js versions 355 | 356 | With `npx` (Comes bundled with npm v5.2.0 or newer) and the [`node-bin`](https://www.npmjs.com/package/node-bin) package, you can easily try out code in different Node.js versions without having to use a version manager like [`nvm`](http://nvm.sh), [`nave`](https://github.com/isaacs/nave), or [`n`](https://github.com/tj/n). 357 | 358 | ``` 359 | $ npx --package=node-bin@6.11.0 -- node --version 360 | v6.11.0 361 | ``` 362 | 363 | ### Link local packages 364 | 365 | Sometimes it can be useful to have a local version of a package as a dependency. You can use `npm link` to link one local package into another. Run `npm link` in the package you want to use. This creates a global reference. Then go into your original package and run `npm link ` to link in the other package. 366 | 367 | ``` 368 | $ cd rainbow 369 | $ npm link 370 | $ cd ../unicorn 371 | $ npm link rainbow 372 | ``` 373 | 374 | You can now use `rainbow` as a dependency in the `unicorn` package. 375 | 376 | ### Install a package from GitHub 377 | 378 | npm supports using a shorthand for installing a package directly from a GitHub repo: 379 | 380 | ``` 381 | $ npm install sindresorhus/chalk 382 | ``` 383 | 384 | Let's target a specific commit as the main branch is a moving target: 385 | 386 | ``` 387 | $ npm install 'sindresorhus/chalk#51b8f32' 388 | ``` 389 | 390 | Specify either a commit SHA, branch, tag, or nothing. 391 | 392 | You can also install Git dependencies with semver: *(Requires npm v5 or newer)* 393 | 394 | ``` 395 | $ npm install 'sindresorhus/chalk#semver:^2.0.0' 396 | ``` 397 | 398 | ### Install a specific version of a package 399 | 400 | ``` 401 | $ npm install chalk@1.0.0 402 | ``` 403 | 404 | 405 | ### List top-level installed packages and their version 406 | 407 | ``` 408 | $ npm ls --depth=0 409 | ``` 410 | 411 | ### Command help 412 | 413 | Get help docs for a command: 414 | 415 | ``` 416 | $ npm help 417 | ``` 418 | 419 | Example: 420 | 421 | ``` 422 | $ npm help install 423 | ``` 424 | 425 | ### Standalone version of a package 426 | 427 | Quickly get a standalone version of a package that is browserified and usable in the browser. 428 | 429 | ``` 430 | https://wzrd.in/standalone/[@] 431 | ``` 432 | 433 | Examples: 434 | 435 | - 436 | - 437 | 438 | Great for prototyping, but download the file or use Browserify yourself for production. 439 | 440 | ## FAQ 441 | 442 | - [Check in node_modules vs. shrinkwrap](http://stackoverflow.com/questions/11459733/check-in-node-modules-vs-shrinkwrap) 443 | - [What is the difference between Bower and npm?](http://stackoverflow.com/questions/18641899/what-is-the-difference-between-bower-and-npm) 444 | - [What does `^` mean in package.json versioning?](http://stackoverflow.com/questions/22137778/what-does-mean-in-package-json-versioning) 445 | - [Find the version of an installed npm package](http://stackoverflow.com/questions/10972176/find-the-version-of-an-installed-npm-package) 446 | - [What's the difference between dependencies, devDependencies, and peerDependencies in package.json?](http://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies) 447 | 448 | ## Community 449 | 450 | - [`#npm` on Freenode](http://webchat.freenode.net/?channels=npm) 451 | - [Stack Overflow](https://stackoverflow.com/questions/tagged/npm) 452 | - [Reddit](https://www.reddit.com/r/npm) 453 | - [Twitter](https://twitter.com/npmjs) 454 | - [Blog](https://blog.npmjs.org) 455 | 456 | ## Documentation 457 | 458 | - [Official](https://docs.npmjs.com) 459 | - [Troubleshooting](https://github.com/npm/npm/wiki/Troubleshooting) 460 | - [Semantic versioning](https://docs.npmjs.com/getting-started/semantic-versioning) 461 | - [Fixing npm permissions](https://docs.npmjs.com/getting-started/fixing-npm-permissions) 462 | - [package.json](https://docs.npmjs.com/files/package.json) 463 | - [npm run script](https://docs.npmjs.com/cli/run-script) 464 | - [Stats API](https://github.com/npm/download-counts) 465 | 466 | ## Support 467 | 468 | - [npm.community](https://npm.community/c/support) 469 | - [Twitter](https://twitter.com/npm_support) 470 | - [Contact form](https://www.npmjs.com/support) 471 | 472 | ## Related 473 | 474 | - [awesome-nodejs](https://github.com/sindresorhus/awesome-nodejs) 475 | --------------------------------------------------------------------------------