Node.js Express安装与使用教程(3)

  • 安装依赖(进入到HelloExpress下,执行npm install)
  • 使用npm start启动网站(express 4.x后)
  • 好啦,我们先安装依赖。这里要先提一下HelloExpress目录下的package.json文件,其内容如下:

    {
     "name": "HelloExpress",
     "version": "0.0.0",
     "private": true,
     "scripts": {
      "start": "node ./bin/www"
     },
     "dependencies": {
      "body-parser": "~1.13.2",
      "cookie-parser": "~1.3.5",
      "debug": "~2.2.0",
      "express": "~4.13.1",
      "jade": "~1.11.0",
      "morgan": "~1.6.1",
      "serve-favicon": "~2.3.0"
     }
    }

    这个文件定义了一个Node.js应用的基本信息,我们这次注意的是 dependencies ,它定义了应用依赖的模块。

    在HelloExpress下执行“npm install”命令,npm会自动找到package.json,分析它,安装所有依赖模块。这要花费一些时间,休息一下,去喝杯茶。

    看看,下面是安装结果:

    G:\nodejs\myprojects\HelloExpress>npm install
    debug@2.2.0 node_modules\debug
    └── ms@0.7.1
    
    cookie-parser@1.3.5 node_modules\cookie-parser
    ├── cookie-signature@1.0.6
    └── cookie@0.1.3
    
    serve-favicon@2.3.0 node_modules\serve-favicon
    ├── fresh@0.3.0
    ├── etag@1.7.0
    ├── parseurl@1.3.0
    └── ms@0.7.1
    
    morgan@1.6.1 node_modules\morgan
    ├── basic-auth@1.0.3
    ├── on-headers@1.0.0
    ├── depd@1.0.1
    └── on-finished@2.3.0 (ee-first@1.1.1)
    
    body-parser@1.13.3 node_modules\body-parser
    ├── content-type@1.0.1
    ├── bytes@2.1.0
    ├── depd@1.0.1
    ├── on-finished@2.3.0 (ee-first@1.1.1)
    ├── qs@4.0.0
    ├── iconv-lite@0.4.11
    ├── http-errors@1.3.1 (inherits@2.0.1, statuses@1.2.1)
    ├── raw-body@2.1.2 (unpipe@1.0.0)
    └── type-is@1.6.6 (media-typer@0.3.0, mime-types@2.1.4)
    
    express@4.13.3 node_modules\express
    ├── escape-html@1.0.2
    ├── merge-descriptors@1.0.0
    ├── array-flatten@1.1.1
    ├── cookie@0.1.3
    ├── cookie-signature@1.0.6
    ├── methods@1.1.1
    ├── utils-merge@1.0.0
    ├── range-parser@1.0.2
    ├── fresh@0.3.0
    ├── path-to-regexp@0.1.7
    ├── vary@1.0.1
    ├── content-type@1.0.1
    ├── etag@1.7.0
    ├── parseurl@1.3.0
    ├── content-disposition@0.5.0
    ├── serve-static@1.10.0
    ├── depd@1.0.1
    ├── qs@4.0.0
    ├── finalhandler@0.4.0 (unpipe@1.0.0)
    ├── on-finished@2.3.0 (ee-first@1.1.1)
    ├── send@0.13.0 (destroy@1.0.3, statuses@1.2.1, ms@0.7.1, mime@1.3.4, http-er
    rors@1.3.1)
    ├── accepts@1.2.12 (negotiator@0.5.3, mime-types@2.1.4)
    ├── type-is@1.6.6 (media-typer@0.3.0, mime-types@2.1.4)
    └── proxy-addr@1.0.8 (forwarded@0.1.0, ipaddr.js@1.0.1)
    
    jade@1.11.0 node_modules\jade
    ├── character-parser@1.2.1
    ├── void-elements@2.0.1
    ├── commander@2.6.0
    ├── constantinople@3.0.2 (acorn@2.1.0)
    ├── mkdirp@0.5.1 (minimist@0.0.8)
    ├── clean-css@3.3.7 (commander@2.8.1, source-map@0.4.4)
    ├── uglify-js@2.4.24 (uglify-to-browserify@1.0.2, async@0.2.10, source-map@0.
    1.34, yargs@3.5.4)
    ├── with@4.0.3 (acorn@1.2.2, acorn-globals@1.0.5)
    ├── transformers@2.1.0 (css@1.0.8, uglify-js@2.2.5, promise@2.0.0)
    └── jstransformer@0.0.2 (is-promise@2.0.0, promise@6.1.0)
    
    G:\nodejs\myprojects\HelloExpress>
          

    内容版权声明:除非注明,否则皆为本站原创文章。

    转载注明出处:http://www.heiqu.com/383.html