Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
12
|
第
2
章
大体来说,包管理器的两个主要职责就是安装包和管理包依赖关系。
npm
是一个快速、能
干、易用的包管理器,
Node
生态能发展得如此迅速和多姿多彩
,我想其中有
npm
很大的
功劳。
另外还有一个很流行的相竞争的包管理器叫
Yarn
,它跟
npm
使用同一个包
数据库。我们将在第
16
章使用
Y
arn
。
如果你是照着先前的步骤安装
Node
,
npm
就会一起安装了,因此,你已经获得
npm
了。
现在可以开始工作了。
你在
npm
中使用的主要命令将是
install
(一点儿也不奇怪)。比如说要安装
nodemon
(一
个流行的工具,用于修改代码时自动重启
Node
应用)
,你就在控制台中运行以下命令:
npm install -g nodemon
-g
参数告诉
npm
,这个包要
全局
安装,意味着在系统中全局可用。等到讨论
package.json
文件的时候,这个差别就会更清楚了。就现在来说,经验法则是
JavaScript
工具
(例如
nodemon
)一般应该全局安装,而那些特定于
We
b
应用或项目的包就不需要这样了。
不像
Python
等语言(
Python
从
2.0
到
3.0
经历了大变更,需要一种办法来
为切换环境提供便利),
Node
平台足够新
,很可能你运行的就是最新版的
Node
。不
过如果你觉得需要支持多版本的
Node
,可以看看
nvm
或
n
,它
们支持切换环境。想知道你的计算机上安装的是什么版本的
Node
,键入
node --version
即可。
2.5
 用
Node
做一个简单的
Web
服务器
如果你曾搭建过静态
HTML
网站,或者有
PHP
或
ASP
背景,很可能熟悉 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099