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

推荐订阅源

Jina AI
Jina AI
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
AI
AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
H
Help Net Security
Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
L
LINUX DO - 最新话题
A
Arctic Wolf
博客园_首页
S
Securelist
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Cyberwarzone
Cyberwarzone
小众软件
小众软件
T
Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Blog — PlanetScale
Blog — PlanetScale
N
News and Events Feed by Topic
NISL@THU
NISL@THU
Forbes - Security
Forbes - Security
博客园 - 聂微东
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
H
Heimdal Security Blog
罗磊的独立博客
S
Security @ Cisco Blogs
B
Blog
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
Hacker News - Newest:
Hacker News - Newest: "LLM"
I
Intezer
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
The Cloudflare Blog
S
Schneier on Security
月光博客
月光博客
L
LINUX DO - 热门话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

老高的博客

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