learn nodeJs

learn nodeJs

下载  node-v0.12.7-x64.msi,安装。

CMD,  检查是否安装成功
D:\work\workspace\test\nodeJS\express_demo>node -v
v0.12.7

安装express模块
npm install express

执行express app命令
报错:
`express` is not recognized as an internal or external command, operable program or batch file.

原因是:

最新版本的express,命令行功能已经转移到模块express-generetor,需要单独安装.

使用如下命令

npm install -g express-generator


进入app文件夹中,执行app,使用命令node app这时候会报错,因为第一次使用express框架的话,缺少很多必备的modules

D:\work\workspace\test\nodeJS\express_demo\app>node app.js


module.js:338
    throw err;
          ^
Error: Cannot find module 'serve-favicon'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (D:\work\workspace\test\nodeJS\express_demo\app\app.js:3:15)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)


依次安装需要的Module
npm install  serve-favicon
npm install  morgan
npm install  cookie-parser
npm install  body-parser
npm install debug
npm install jade
安装完成所有必备的modules后,在此执行app,项目根目录下 npm start 命令
还是报下面的错误:
Error: Cannot find module 'jade'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at new View (D:\work\workspace\test\nodeJS\node_modules\express\lib\view.js:78:30)
    at EventEmitter.render (D:\work\workspace\test\nodeJS\node_modules\express\lib\application.js:569:12)
    at ServerResponse.render (D:\work\workspace\test\nodeJS\node_modules\express\lib\response.js:961:7)
    at D:\work\workspace\test\nodeJS\express_demo\app\app.js:53:7
    at Layer.handle_error (D:\work\workspace\test\nodeJS\node_modules\express\lib\router\layer.js:71:5)
    at trim_prefix (D:\work\workspace\test\nodeJS\node_modules\express\lib\router\index.js:310:13)


最后发现了原因 ,这个Jade必要放在express 的Modules目录下面。CD到这个目录并install.
D:\work\workspace\test\nodeJS\node_modules\express\node_modules>npm install jade
然后再回到之前的目录并启动
D:\work\workspace\test\nodeJS\express_demo\app>npm start
这回没问题了,
D:\work\workspace\test\nodeJS\express_demo\app>npm start
> [email protected] start D:\work\workspace\test\nodeJS\express_demo\app
> node ./bin/www
GET / 200 373.915 ms - 170
GET /stylesheets/style.css 200 3.740 ms - 111
浏览器输入 http://127.0.0.1:3000/
会出现
Welcome to Express


眼镜蛇

你可能感兴趣的:(learn nodeJs)