Tento dokument m├┤┼że by┼ą v porovnan├ş s dokument├íciou v angli─Źtine zastaral├Ż. Aktu├ílne inform├ície n├íjdete v dokument├ícii v angli─Źtine.

Ôťľ

Debuggovanie Express

Express interne pou┼ż├şva k logovaniu inform├íci├ş oh─żadom route matchingu, pou┼żit├Żch middleware funkci├ích, aplika─Źn├ęho m├│du a toku request response cyklu modul debug.

debug je ako roz┼í├şrena verzia console.log, ale narozdiel od console.log, nemus├şte zakomentov├íva┼ą volania debug v produk─Źnom k├│de. Logovanie je vypnut├ę defaultne a je mo┼żn├ę ho zapn├║┼ą pou┼żit├şm DEBUG environment premennej.

Ak chcete vidie┼ą v┼íetky intern├ę logy Express-u, nastavte pri sp├║┼ítan├ş va┼íej aplik├ície environment premenn├║ DEBUG na hodnotu express:*.


$ DEBUG=express:* node index.js

Na Windows-e pou┼żite nasleduj├║ci pr├şkaz.


> set DEBUG=express:* & node index.js

Spusten├şm tohto pr├şkazu v pr├şpade defaultnej aplik├ície vygenerovanej pomocou express gener├ítora vyp├ş┼íe nasleduj├║ci v├Żstup:


$ DEBUG=express:* node ./bin/www
  express:router:route new / +0ms
  express:router:layer new / +1ms
  express:router:route get / +1ms
  express:router:layer new / +0ms
  express:router:route new / +1ms
  express:router:layer new / +0ms
  express:router:route get / +0ms
  express:router:layer new / +0ms
  express:application compile etag weak +1ms
  express:application compile query parser extended +0ms
  express:application compile trust proxy false +0ms
  express:application booting in development mode +1ms
  express:router use / query +0ms
  express:router:layer new / +0ms
  express:router use / expressInit +0ms
  express:router:layer new / +0ms
  express:router use / favicon +1ms
  express:router:layer new / +0ms
  express:router use / logger +0ms
  express:router:layer new / +0ms
  express:router use / jsonParser +0ms
  express:router:layer new / +1ms
  express:router use / urlencodedParser +0ms
  express:router:layer new / +0ms
  express:router use / cookieParser +0ms
  express:router:layer new / +0ms
  express:router use / stylus +90ms
  express:router:layer new / +0ms
  express:router use / serveStatic +0ms
  express:router:layer new / +0ms
  express:router use / router +0ms
  express:router:layer new / +1ms
  express:router use /users router +0ms
  express:router:layer new /users +0ms
  express:router use / <anonymous> +0ms
  express:router:layer new / +0ms
  express:router use / <anonymous> +0ms
  express:router:layer new / +0ms
  express:router use / <anonymous> +0ms
  express:router:layer new / +0ms

N├ísledne, ke─Ć aplik├ícia odchyt├ş request, uvid├şte nasleduj├║ce logy ┼ípecifikovan├ę v Express k├│de:


  express:router dispatching GET / +4h
  express:router query  : / +2ms
  express:router expressInit  : / +0ms
  express:router favicon  : / +0ms
  express:router logger  : / +1ms
  express:router jsonParser  : / +0ms
  express:router urlencodedParser  : / +1ms
  express:router cookieParser  : / +0ms
  express:router stylus  : / +0ms
  express:router serveStatic  : / +2ms
  express:router router  : / +2ms
  express:router dispatching GET / +1ms
  express:view lookup "index.pug" +338ms
  express:view stat "/projects/example/views/index.pug" +0ms
  express:view render "/projects/example/views/index.pug" +1ms

Ak chcete vidie┼ą iba logy z router implement├ície, nastavte hodnotu premennej DEBUG na express:router. Podobne, ak chcete vidie┼ą iba logy z implement├ície aplik├ície, nastavte hodnotu premennej DEBUG na express:application at─Ć.

Aplik├ície vygenerovan├ę pr├şkazom express

Aplik├ícia vygenerovan├í pr├şkazom express taktie┼ż pou┼ż├şva modul debug a jej debug namespace je dostupn├Ż pod n├ízvom aplik├ície.

Pomocou nasleduj├║ceho pr├şkazu, dok├í┼żete povoli┼ą debug v├Żpisy pre aplik├íciu vygenerovan├║ pomocou $ express sample-app takto:


$ DEBUG=sample-app:* node ./bin/www

Pomocou ─Źiarkou oddelen├ęho zoznamu n├ízvov m├┤┼żete ┼ípecifikova┼ą viac ako jeden debug namespace:


$ DEBUG=http,mail,express:* node index.js

Pre viac inform├íci├ş oh─żadom debug modulu si pozrite debug.