您的位置:首页 > Web前端 > Node.js

Mac 安装Node.js Express轻量级框架

2014-11-23 17:50 417 查看
系统版本: OS X 10.10.1 (14B25)

内核版本: Darwin 14.0.0
npm版本:   1.4.2

Mac 调出控制台工具 输入: 
sudo npm install -g express
(-g 代表全局安装)

稍后控制台输出如下:
yuzaideMacBook-Pro:~ yuzai$ sudo npm install -g express

Password:

express@4.10.2 /usr/local/lib/node_modules/express

├── utils-merge@1.0.0

├── merge-descriptors@0.0.2

├── fresh@0.2.4

├── cookie@0.1.2

├── escape-html@1.0.1

├── range-parser@1.0.2

├── cookie-signature@1.0.5

├── finalhandler@0.3.2

├── vary@1.0.0

├── media-typer@0.3.0

├── parseurl@1.3.0

├── methods@1.1.0

├── serve-static@1.7.1

├── content-disposition@0.5.0

├── path-to-regexp@0.1.3

├── depd@1.0.0

├── qs@2.3.2

├── proxy-addr@1.0.3 (forwarded@0.1.0, ipaddr.js@0.1.3)

├── on-finished@2.1.1 (ee-first@1.1.0)

├── debug@2.1.0 (ms@0.6.2)

├── etag@1.5.1 (crc@3.2.1)

├── send@0.10.1 (destroy@1.0.3, ms@0.6.2, mime@1.2.11)

├── type-is@1.5.3 (mime-types@2.0.3)

└── accepts@1.1.3 (negotiator@0.4.9, mime-types@2.0.3)

创建示例工程华丽报错 请执行以下指令
npm install -g express-generator

yuzaideMacBook-Pro:node yuzai$ sudo npm install -g express-generator
Password:
/usr/local/bin/express -> /usr/local/lib/node_modules/express-generator/bin/express
express-generator@4.9.0 /usr/local/lib/node_modules/express-generator
├── mkdirp@0.5.0 (minimist@0.0.8)
└── commander@1.3.2 (keypress@0.1.0)

继续报错
Error: Cannot find module 

解决办法:
npm install -d

创建示例工程

yuzaideMacBook-Pro:sdk yuzai$ express  hole

   create : hole
   create : hole/package.json
   create : hole/app.js
   create : hole/public
   create : hole/public/javascripts
   create : hole/public/images
   create : hole/public/stylesheets
   create : hole/public/stylesheets/style.css
   create : hole/routes
   create : hole/routes/index.js
   create : hole/routes/users.js
   create : hole/views
   create : hole/views/index.jade
   create : hole/views/layout.jade
   create : hole/views/error.jade
   create : hole/bin
   create : hole/bin/www

   install dependencies:
     $ cd hole && npm install

   run the app:
     $ DEBUG=hole ./bin/www

运行程序

yuzaideMacBook-Pro:hole yuzai$ npm start

使用浏览器访问  http://127.0.0.1:3000/ 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: