ÒÔÏÂͨ¹ýÁ½ÖÖ·½Ê½½éÉÜwindowsÏ°²×°node.js¼°¿ò¼Üexpress
µÚÒ»ÖÖ·½Ê½£º
×ܹ²·ÖΪËIJ½ÇáËÉÍê³ÉNodejsµÄExpress°²×°
µÚÒ»²½¡¢°²×°
ËùÓÐÒªÏÈ°´×°express-generator£¬·ñÔò´´½¨ÏîĿʱ£¬»áÌáʾexpressÃüÁîûÕÒµ½
npm install -g express-generator #ÐèÏÈ°²×°express-generator npm install -g express express -V #ÑéÖ¤ÊÇ·ñ°²×°³É¹¦
µÚ¶þ²½¡¢´´½¨ÏîÄ¿
$ express myfirstexpress # expressµÄĬÈÏÄ£°æ²ÉÓÃjade£¬ÈôÐèÒªejsÄ£°æÖ§³Ö£¬¼ÓÉÏ-eÑ¡Ï¼´ express -e myfirstexpress $ cd myfirstexpress $ ls app.js bin package.json public routes views #ÏîÄ¿µÄĿ¼½á¹¹
µÚÈý²½¡¢ÔËÐÐÏîÄ¿
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
$ npm install #ÐèÒªµÈ´ýÒ»¶Îʱ¼ä£¬ÒòΪÐèÒª»ñÈ¡ºÜ¶àµÄ¿âÎļþ
$ npm start
µÚËIJ½¡¢·ÃÎʵÚÒ»¸öexpressÏîÄ¿
ä¯ÀÀÆ÷ÖÐÊäÈë http://127.0.0.1:3000
µÚ¶þÖÖ·½·¨£¨ÎÄ×Ö˵Ã÷ºÍͼƬÏà½áºÏ£©£º
Ö÷Ҫͨ¹ýÒÔÏÂÎå²½Íê³ÉNodejsµÄExpress°²×°
µÚÒ»²½£º°²×°expressÄ£¿é£¬cdµ½Îļþ¼ÐÖУ¬Ê¹ÓÃnpm install expressÃüÁî°²×°express moduleºó£¬»á·¢ÏÖÎļþ¼ÐÖжàÁËnode_modulesĿ¼£¬Àï±ß»áÓÐexpressÄ£¿éÁË¡£
µÚ¶þ²½£º½øÈëµ½ÈÎÒâÒ»¸öÎļþ¼Ð£¬Ö´ÐÐexpress appÃüÁ¾Í»á´´½¨Ò»¸öappµÄÓ¦ÓÃÏîÄ¿£¬½á¹¹ÈçÏÂ
E:nodejsexpress_demo>express app
create : app
create : app/package.json
create : app/app.js
create : app/public
create : app/bin
create : app/bin/www
create : app/public/stylesheets
create : app/public/stylesheets/style.css
create : app/views
create : app/views/index.jade
create : app/views/layout.jade
create : app/views/error.jade
create : app/public/images
create : app/routes
create : app/routes/index.js
create : app/routes/users.js
create : app/public/javascripts
install dependencies: (ÕâÀïָʾ°²×°±Ø±¸µÄ°ü)
$ cd app && npm install
run the app: (ÕâÀïָʾִÐУ¬Ê¹ÓÃnpm start)
$ DEBUG=app ./bin/www
µÚÈý²½£ºcd½øÈëappÎļþ¼ÐÖУ¬Ö´ÐÐapp,ʹÓÃÃüÁînode appÕâʱºò»á±¨´í£¬ÒòΪµÚÒ»´ÎʹÓÃexpress¿ò¼ÜµÄ»°£¬È±Éٺܶà±Ø±¸µÄmodules
±¨´í£º
module.js:340
throw err;
^
Error: Cannot find module 'serve-favicon'//±íʾȱÉÙserve-faviconÄ£¿é
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (E:nodejsNode.jså¼åå®æchapter_twoexpress_dem
oappapp.js:3:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
µÚËIJ½£ºÕâ¸öʱºò¸ù¾ÝÌáʾ£¬°²×°±Ø±¸µÄmodules¾Í¿ÉÒÔÁË£¬Èçͼ
Your environment has been set up for using Node.js 0.10.26 (ia32) and npm.
C:UsersAdministrator>e:
E:>cd nodejs
E:nodejs>npm install serve-favicon
serve-favicon@2.2.0 node_modulesserve-favicon
©À©¤©¤ ms@0.7.0
©À©¤©¤ parseurl@1.3.0
©À©¤©¤ fresh@0.2.4
©¸©¤©¤ etag@1.5.1 (crc@3.2.1)
E:nodejs>npm install morgan
morgan@1.5.1 node_modulesmorgan
©À©¤©¤ basic-auth@1.0.0
©À©¤©¤ depd@1.0.0
©À©¤©¤ debug@2.1.1 (ms@0.6.2)
©¸©¤©¤ on-finished@2.2.0 (ee-first@1.1.0)
E:nodejs>npm install cookie-parser
cookie-parser@1.3.3 node_modulescookie-parser
©¸©¤©¤ cookie-signature@1.0.5
E:nodejs>npm install body-parser
body-parser@1.12.0 node_modulesbody-parser
©À©¤©¤ content-type@1.0.1
©À©¤©¤ raw-body@1.3.3
©À©¤©¤ bytes@1.0.0
©À©¤©¤ depd@1.0.0
©À©¤©¤ qs@2.3.3
©À©¤©¤ iconv-lite@0.4.7
©À©¤©¤ on-finished@2.2.0 (ee-first@1.1.0)
©À©¤©¤ debug@2.1.1 (ms@0.6.2)
©¸©¤©¤ type-is@1.6.0 (media-typer@0.3.0, mime-types@2.0.9)
E:nodejs>
µÚÎå²½£º°²×°Íê³ÉËùÓбر¸µÄmodulesºó£¬ÔÚ´ËÖ´ÐÐapp£¬ÏîÄ¿¸ùĿ¼ÏÂnpm startÃüÁÈç¹û»¹ÊÇÌáʾÀàËÆError: Cannot find module 'jade'´íÎóµÄ»°£¬¼ÌÐø°²×°±Ø±¸µÄÄ£¿é
µÚÁù²½£ºÒÔÉÏËùÓеÄÒ»ÇÐÍê³Éºó£¬ÔÚä¯ÀÀÆ÷ÏÂÊäÈëhttp://127.0.0.1:3000/£¬ÈçÏÂͼ¾Í±íʾ³É¹¦ÁË¡£
ÒÔÉÏÊÇwindowsÏ°²×°nodejs¼°¿ò¼ÜexpressµÄÈ«²¿ÄÚÈÝ£¬Ï£Íû´ó¼Òϲ»¶¡£