Awesome npm resources and tips
npm is a package manager for the JavaScript programming language and comes bundled in the Node.js runtime.
Please read the contribution guidelines before contributing.
npm publish.$ npm install --global npm
npm i → npm installnpm i -D → npm install --save-devnpm t → npm testnpm it → npm install && npm testnpm r → npm uninstallnpm un → npm uninstallnpm up → npm updateSpeed up your common npm tasks.
In your .zshrc/.bashrc:
alias ni='npm install' alias nid='npm install --save-dev' alias nig='npm install --global' alias nt='npm test' alias nit='npm install && npm test' alias nk='npm link' alias nr='npm run' alias ns='npm start' alias nf='npm cache clean && rm -rf node_modules && npm install' alias nlg='npm list --global --depth=0'
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:
$ npm install --save-dev ava
You can easily run scripts using npm by adding them to the "scripts" field in package.json and run them with npm run <script-name>. Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH, so you can run them by name.
{ "name": "awesome-package", "scripts": { "cat": "cat-names" }, "dependencies": { "cat-names": "^1.0.0" } }
$ npm run cat
Max
All package.json properties are exposed as environment variables:
{ "name": "awesome-package", "scripts": { "name": "echo $npm_package_name" } }
$ npm run name
awesome-package
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, so npm run will just ignore it and pass it to the command.
{ "name": "awesome-package", "scripts": { "xo": "xo", "xo:fix": "npm run xo -- --fix", } }
Adding the -- --fix option is like executing xo --fix.
npm run has a --silent option which is especially useful when combining npm scripts.
Imagine you have a setup for linting your JavaScript files like the following:
{ "name": "awesome-package", "scripts": { "xo": "xo", "xo:fix": "npm run xo --silent -- --fix", } }
Using the --silent option reduces the output in the terminal. See this comparison.
npm comes with predefined lifecyle scripts which are excuted under specific conditions if they are defined in your package.json.
{ "name": "awesome-package", "scripts": { "prepublishOnly": "nsp check" }, "devDependencies": { "nsp": "^3.0.0" } }
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.
Note: prepublishOnly is available since npm v4.0.0. See npm docs.
npm start and npm testnpm start and npm test are also lifecycle scripts but are not executed automatically.
{ "name": "awesome-package", "scripts": { "start": "node server.js", "test": "ava" }, "devDependencies": { "ava": "^1.0.0" } }
Therefore they can be executed simply with:
$ npm test $ npm start
pre and post scriptsThese are special lifecycle scripts which can be used to run scripts automatically in sequence.
{ "name": "awesome-package", "scripts": { "pretest": "eslint .", "test": "ava" }, "devDependencies": { "eslint": "^4.19.0", "ava": "^1.0.0" } }
$ npm test
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.
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.
npxnpm comes bundled 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,


企业专属的AI法律顾问
iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模型免费使用,一键生成无水印视频


实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。


选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


最强AI数据分析助手
小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。


像人一样思考的AI智能体
imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。


AI数字人视频创作平台
Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。


一站式AI创作平台
提供 AI 驱动的图片、视频生成及数字人等功能,助力创意创作
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号