nodejs学习资料 - 第二节:npm包管理&REPL交互命令输入

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
  • 查看 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"
}

清空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

我的博客

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ## 前端开发的工具 ### 编辑器: 1. 轻量级的,依靠插件:sublime;atom(github);vs ...
    浪流儿阅读 8,557评论 0 2
  • 大家好,我是IT修真院深圳分院第3期的学员,一枚正直纯洁善良的前端程序员,今天给大家分享一下,修真院官网前端工程师...
    大大头大阅读 8,032评论 0 1
  • 什么是 NPM npm之于Node,就像pip之于Python,gem之于Ruby,composer之于PHP。 ...
    ihoey阅读 11,391评论 2 36
  • NPM 使用介绍NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场...
    Dora404阅读 4,453评论 0 1
  • 我拿青春做赌注 明天,你会回来 执着地停滞时间 秋风打招呼 我不觉 秋雨示意 我沐浴素颜 当身边的金灿 入侵一直张...
    带露珠的翅膀阅读 2,372评论 0 7

友情链接更多精彩内容