AngularJS 1.x系列:Node.js安装及npm常用命令(1)

1. Node.js安装

1.1 Node.js下载

  Node.js官网:https://nodejs.org

  当前下载版本(含npm):Latest LTS Version: v6.10.3 (includes npm 3.10.10)

1.2 Node.js及npm查看版本

  安装Node.js之后,查看Node.js及npm版本。

node -v
npm -v

2. npm常用命令

  npm(node package manager),node包管理器,主要功能是管理node包,包括:安装、卸载、更新、查看、搜索、发布等。

  npm官网文档:https://docs.npmjs.com/ 

2.1 npm配置

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

2.2 npm包管理

  ◊ npm init:在项目中引导创建一个package.json文件

npm init [-f|--force|-y|--yes]
PS F:\Projects\Libing.Portal> 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: (Libing.Portal) libing.portal
version: (1.0.0)
description:
entry point: (index.js) main.js
test command:
git repository:
keywords:
author: libing
license: (ISC) MIT
About to write to F:\Projects\Libing.Portal\package.json:
{
  "name": "libing.portal",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "libing",
  "license": "MIT"
}


Is this ok? (yes)

  ◊ npm install:安装包

  npm install命令参数形式:

npm install --help
npm install (with no args, in package dir)
npm install [<@scope>/]<pkg>
npm install [<@scope>/]<pkg>@<tag>
npm install [<@scope>/]<pkg>@<version>
npm install [<@scope>/]<pkg>@<version range>
npm install <folder>
npm install <tarball file>
npm install <tarball url>
npm install <git:// url>
npm install <github username>/<github project>

aliases: i, isntall
common options: [--save|--save-dev|--save-optional] [--save-exact]

  示例:

npm install angular

  运行之后将创建文件夹node_modules,默认安装包最新版本。

  指定安装包版本:

npm install angular@1.2.32

  -S, --save 安装包信息将加入到dependencies(生产阶段的依赖):

npm install angular -S
"dependencies": {
  "angular": "^1.6.4"
},

  -D, --save-dev 安装包信息将加入到devDependencies(开发阶段的依赖):

npm install angular -D
"devDependencies": {
  "angular": "^1.6.4"
}

  安装包的依赖都被写入了package.json文件后,可以使用npm install根据dependencies配置安装全部依赖包。

npm install

  ◊ npm uninstall:卸载包

  npm uninstall命令参数形式:

npm uninstall -help
npm uninstall [<@scope>/]<pkg>[@<version>]... [--save|--save-dev|--save-optional]
npm uninstall angular -S

  ◊ npm list:查看全部已安装包

npm list

  ◊ npm outdated检查包是否过时

npm outdated

  ◊ npm update:更新包

npm update [-g] [<pkg>...]

  ◊ npm view:查看包的注册信息

npm view [<@scope>/]<pkg>[@<version>] [<field>[.subfield]...]
npm view angular

  npm view angular dependencies:查看包的依赖关系

  npm view angular repository.url:查看包的源文件地址

posted @ 2017-05-27 08:28  libingql  阅读(2910)  评论(0编辑  收藏  举报