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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
N
News | PayPal Newsroom
SecWiki News
SecWiki News
P
Privacy International News Feed
T
Troy Hunt's Blog
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
L
LINUX DO - 热门话题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Security Latest
Security Latest
AWS News Blog
AWS News Blog
S
Secure Thoughts
W
WeLiveSecurity
H
Heimdal Security Blog
T
Threat Research - Cisco Blogs
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
G
GRAHAM CLULEY
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
L
Lohrmann on Cybersecurity
C
CERT Recently Published Vulnerability Notes
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
Cisco Talos Blog
Cisco Talos Blog
雷峰网
雷峰网
Cloudbric
Cloudbric
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
Latest news
Latest news
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
D
Docker
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
H
Help Net Security
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Check Point Blog
博客园 - 叶小钗

老高的博客

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