Kuv siv xav tau li cas hauv node JS?
Kuv siv xav tau li cas hauv node JS?

Video: Kuv siv xav tau li cas hauv node JS?

Video: Kuv siv xav tau li cas hauv node JS?
Video: Merging PDFs with Python! 2024, Hlis ntuj nqeg
Anonim

Koj tuaj yeem xav txog qhov xav tau module raws li cov lus txib thiab lub module module raws li lub organizer ntawm tag nrho cov yuav tsum tau modules. Yuav tsum muaj module hauv Node tsis yog qhov nyuaj ntawm lub tswvyim. const config = xav tau ('/path/to/file'); Lub ntsiab khoom exported los ntawm lub xav tau module yog ib txoj haujlwm (raws li siv hauv qhov piv txwv saum toj no).

Xav txog qhov no, dab tsi yuav tsum tau ua hauv node JS?

xav tau yog siv los noj cov modules. Nws tso cai rau koj suav nrog cov modules hauv koj cov kev pab cuam. Koj tuaj yeem ntxiv cov tub ntxhais built-in Node . js modules, community-based modules (node_modules), and local modules.

Tsis tas li ntawd, peb puas tuaj yeem siv ntshuam hauv Nodejs? Kev xa tawm CommonJS npm Modules Cov ntshuam thiab export keywords yog ib feem ntawm ECMAScript Modules spec, lossis ESM luv luv. Feem ntau Node. js ua project yog sau siv CommonJS, siv qhov xav tau () ua haujlwm rau ntshuam lwm cov ntaub ntawv.

Tom qab ntawd, ib tug kuj yuav nug, Kuv yuav siv node js modules li cas?

  1. Built-in Modules. Node.
  2. suav nrog Modules. Txhawm rau suav nrog ib qho module, siv qhov xav tau () ua haujlwm nrog lub npe ntawm lub module:
  3. Tsim koj tus kheej Modules. Koj tuaj yeem tsim koj tus kheej modules, thiab yooj yim suav nrog lawv hauv koj daim ntawv thov.
  4. suav nrog koj tus kheej Module.

Node JS yog dab tsi rau dummies?

Node . js yog qhov qhib-qhov server sab runtime ib puag ncig ua rau ntawm Chrome's V8 JavaScript cav. Nws muab ib qho kev tshwm sim uas tau tsav, tsis thaiv (asynchronous) I / O thiab hla-platform runtime ib puag ncig rau kev tsim kom muaj peev xwm ua tau zoo rau cov ntawv thov sab nraud siv JavaScript.

Pom zoo: