惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
GRAHAM CLULEY
T
Tenable Blog
Know Your Adversary
Know Your Adversary
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
S
Security Affairs
NISL@THU
NISL@THU
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Schneier on Security
Schneier on Security
S
SegmentFault 最新的问题
S
Schneier on Security
G
Google Developers Blog
V
V2EX
C
Check Point Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
S
Secure Thoughts
博客园 - 司徒正美
Recorded Future
Recorded Future
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
AI
AI
博客园 - 聂微东
N
News and Events Feed by Topic
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
Project Zero
Project Zero
W
WeLiveSecurity
博客园 - Franky

老高的博客

WPF 自定义枚举编辑控件 - 老高的博客 2025年度开发趋势有感 - 老高的博客 2025 年终总结 - 老高的博客 MVVM 模式是什么? - 老高的博客 2024 年终总结 - 老高的博客 《飞驰人生2》观后感 - 老高的博客 2023 年终总结 - 老高的博客 项目总结:前后端分离的公司主页站点 - 老高的博客 C# 版本特性记录 - 老高的博客 2022 年终总结 - 老高的博客 在树莓派的 openSUSE 上安装 Nginx - 老高的博客 在树莓派的 openSUSE 上安装 .NET 6 2021 年终总结 - 老高的博客 从零开始学Python - 02.容器类型 - 老高的博客 让文章更生动 - 老高的博客 2020 年终总结 - 老高的博客 2019 年终总结 - 老高的博客 从零开始学Python - 01.基本类型 - 老高的博客 为站点添加把锁 - 老高的博客
npm入门 - 老高的博客
2018-02-02 · via 老高的博客

目标

  • 理解npm的功能
  • 掌握常用npm命令

npm是什么?

npm is the package manager for javascript

这是npm官网上面的说明,它是一个“包管理器”,我们可以利用它编译、发布自己的包,或者从npm的服务器上下载我们需要的包。

我们可以如何利用npm?

作为普通开发者,我们绝大多数的应用场景只是利用npm将我们需要的包安装到本地,然后利用这些包开发我们自己的应用。

安装npm

The npm command-line tool is bundled with Node.js. If you have it installed, then you already have npm.

npm是和Node.js捆绑的,所以我们需要通过Node.js的下载页面来下载安装。

如何选择版本

与其他的开源社区不同,javascript社区呈现一种激进的态势,基本所有的库都在快速迭代,而使用者也倾向于积极更新,因此在安装时我们选择当前版本还是LTS版本显得不那么重要。按照个人习惯,我会选择LTS版本。

常用命令

–version、-v

返回当前已安装的npm的版本。

install

shell

1
npm install [-g] <name>[@<version>] [[-P | --save-prod] | [-D | --save-dev]]

安装指定名称的包。

  • -g : 全局安装(可选)
  • <name> : 包的名称
  • @<version> : 包的版本(可选)
  • -P | --save-prod : 将包的名称和版本号添加到package.json文件的dependencies部分。
  • -D | --save-dev : 将包的名称和版本号添加到package.json文件的devdependencies部分。
  • -P和-D用来区分产品依赖包与开发依赖包,当我们在一个新环境中执行npm install --production则npm只会帮我们安装dependencies部分的包;如果执行npm install则dependencies和devdependencies部分的包都会被安装。

ls

列出所有已安装的包。

  • -g : 全局安装(可选)

uninstall

shell

1
npm uninstall [-g] <name>[@<version>]

卸载指定名称的包。

  • -g : 全局安装(可选)
  • <name> : 包的名称
  • @<version> : 包的版本(可选)

update

shell

1
npm update [-g] [<pkg>...]

更新指定的包。

comments powered by