nodejs学习资料 - 第二节:npm包管理&REPL

2016-11-29  本文已影响13人  会煮咖啡的猫咪

npm包管理

安装模块

输入

$ npm install express

install 方式用来安装模块
-g 是全局安装, 不加安装在当前node_modules目录中

查询已安装的模块

输入

$ npm ls -g

卸载模块

$ npm uninstall express

更新模块

$ npm update express

搜索模块

$ npm search express

创建模块

npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (02-npm) npm-module
version: (1.0.0) 1.0.0
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /Users/hans/Documents/project/JavaScriptCodes/nodejs-do/02-npm/package.json:

{
  "name": "npm-module",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this ok? (yes) yes
{
  "name": "npm-module",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

清空NPM本地缓存

$ npm cache clear

使用淘宝 NPM 镜像

安装 cnpm

$ npm install -g cnpm --registry=https://registry.npm.taobao.org

使用

$ cnpm install [name]

REPL 交互式命令行

表达式计算

> x = 7
7
> y = 10
10
> x + y
17
> var yy = _
undefined
> console.log(yy)
17
undefined

自动识别多行

> do {
... x++;
... console.log(x);
... }while(x < 20);
8
9
10
11
12
13
14
15
16
17
18
19
20

常用命令

ctrl + c - 退出当前终端。
ctrl + c 按下两次 - 退出 Node REPL。
ctrl + d - 退出 Node REPL.
向上/向下 键 - 查看输入的历史命令
tab 键 - 列出当前命令
.help - 列出使用命令
.break - 退出多行表达式
.clear - 退出多行表达式
.save filename - 保存当前的 Node REPL 会话到指定文件
.load filename - 载入当前 Node REPL 会话的文件内容。

代码

https://github.com/hans007/JavaScriptCodes/tree/master/nodejs-do

我的博客

上一篇下一篇

猜你喜欢

热点阅读