node.js的简单例子

本实例摘抄 : http://blog.csdn.net/u014595019/article/details/50845726

按照本篇文章的例子会出现以下错误。

错误是因为缺少包,按照解决办法依次解决即可!

Error: Cannot find module ‘express’

    at Function.Module._resolveFilename (module.js:469:15)

    at Function.Module._load (module.js:417:25)

    at Module.require (module.js:497:17)

    at require (internal/module.js:20:19)

    at Object.<anonymous> (/Users/abai/nodewww/tests/test.js:2:27)

    at Module._compile (module.js:570:32)

    at Object.Module._extensions..js (module.js:579:10)

    at Module.load (module.js:487:32)

    at tryModuleLoad (module.js:446:12)

    at Function.Module._load (module.js:438:3)

解决办法:

sudo npm install express

Error: Cannot find module ‘body-parser’

    at Function.Module._resolveFilename (module.js:469:15)

    at Function.Module._load (module.js:417:25)

    at Module.require (module.js:497:17)

    at require (internal/module.js:20:19)

    at Object.<anonymous> (/Users/abai/nodewww/tests/test.js:4:27)

    at Module._compile (module.js:570:32)

    at Object.Module._extensions..js (module.js:579:10)

    at Module.load (module.js:487:32)

    at tryModuleLoad (module.js:446:12)

    at Function.Module._load (module.js:438:3)

解决办法: sudo npm install body-parser

Error: Cannot find module ‘cookie-parser’

    at Function.Module._resolveFilename (module.js:469:15)

    at Function.Module._load (module.js:417:25)

    at Module.require (module.js:497:17)

    at require (internal/module.js:20:19)

    at Object.<anonymous> (/Users/abai/nodewww/tests/test.js:5:27)

    at Module._compile (module.js:570:32)

    at Object.Module._extensions..js (module.js:579:10)

    at Module.load (module.js:487:32)

    at tryModuleLoad (module.js:446:12)

    at Function.Module._load (module.js:438:3)

解决办法:sudo npm install cookie-parser

运行项目  node test.js

浏览器输入:http://127.0.0.1:3000/  即可体验node.js 带来的乐趣了

github地址:https://github.com/abaiweb/tests.git