Altamira
Node.js Module
Resolution
Jeff Kunkle
April 19, 2012
Path Resolution
require(“./mymodule.js”);
1
mymodule.js
/projects/preso/
main.js
require(“./mymodule.js”);
require(“./mymodule”);
2
/projects/preso/
main.js
require(“./mymodule”);
mymodule.js
/projects/preso/
main.js
require(“./mymodule”);
mymodule.js
/projects/preso/
mymodule.json
main.js
require(“./mymodule”);
mymodule.js
/projects/preso/
mymodule.json
mymodule.node
main.js
require(“./mymodule”);
require(“./mymodule”);
/projects/preso/
main.js
mymodule/
package.json
init.js
require(“./mymodule”);
mymodule/
/projects/preso/
index.js
main.js
require(“./mymodule”);
mymodule/
/projects/preso/
index.node
main.js
require(“mymodule”);
3
require(“mymodule”);
node_modules/
/usr/local/node/lib/
index.js
mymodule/
* assuming mymodule was a core Node.js module
require(“mymodule”);
node_modules/
/projects/preso/
index.js
main.js
mymodule/
require(“mymodule”);
node_modules/
/projects/
index.js
main.js
mymodule/
preso/
require(“mymodule”);
node_modules/
/
index.js
main.js
mymodule/
projects/
preso/
require(“mymodule”);
Global load paths also exist,
but don’t use them.
Dependency
Resolution Magic!
A
B
C
v1.0
v2.0
a/
node_modules/
c/
b/
node_modules/
c/
b.js
a.js
c.js
c.js
./node_modules/
v1.0
v2.0
a/
b/
b.js
a.js
./node_modules/
c/
c.js
Jeff Kunkle
@kunklejr
Node.js Module Resolution by visual example
Prochain SlideShare
Chargement dans…5
×

Node.js Module Resolution by visual example

1 467 vues

Publié le

Node.js has a very clever design for module path resolution and code loading. Most languages punt when asked to load two modules depending on different versions of a shared third module, but not Node. This presentation depicts a handful of module loading scenarios by demonstrating the filesystem layout for each.

Publié dans : Technologie, Art & Photos
0 commentaire
1 j’aime
Statistiques
Remarques
  • Soyez le premier à commenter

Aucun téléchargement
Vues
Nombre de vues
1 467
Sur SlideShare
0
Issues des intégrations
0
Intégrations
15
Actions
Partages
0
Téléchargements
13
Commentaires
0
J’aime
1
Intégrations 0
Aucune incorporation

Aucune remarque pour cette diapositive

Node.js Module Resolution by visual example

  1. 1. Altamira Node.js Module Resolution Jeff Kunkle April 19, 2012
  2. 2. Path Resolution
  3. 3. require(“./mymodule.js”); 1
  4. 4. mymodule.js /projects/preso/ main.js require(“./mymodule.js”);
  5. 5. require(“./mymodule”); 2
  6. 6. /projects/preso/ main.js require(“./mymodule”);
  7. 7. mymodule.js /projects/preso/ main.js require(“./mymodule”);
  8. 8. mymodule.js /projects/preso/ mymodule.json main.js require(“./mymodule”);
  9. 9. mymodule.js /projects/preso/ mymodule.json mymodule.node main.js require(“./mymodule”);
  10. 10. require(“./mymodule”); /projects/preso/ main.js mymodule/ package.json init.js
  11. 11. require(“./mymodule”); mymodule/ /projects/preso/ index.js main.js
  12. 12. require(“./mymodule”); mymodule/ /projects/preso/ index.node main.js
  13. 13. require(“mymodule”); 3
  14. 14. require(“mymodule”); node_modules/ /usr/local/node/lib/ index.js mymodule/ * assuming mymodule was a core Node.js module
  15. 15. require(“mymodule”); node_modules/ /projects/preso/ index.js main.js mymodule/
  16. 16. require(“mymodule”); node_modules/ /projects/ index.js main.js mymodule/ preso/
  17. 17. require(“mymodule”); node_modules/ / index.js main.js mymodule/ projects/ preso/
  18. 18. require(“mymodule”); Global load paths also exist, but don’t use them.
  19. 19. Dependency Resolution Magic!
  20. 20. A B C v1.0 v2.0
  21. 21. a/ node_modules/ c/ b/ node_modules/ c/ b.js a.js c.js c.js ./node_modules/ v1.0 v2.0
  22. 22. a/ b/ b.js a.js ./node_modules/ c/ c.js
  23. 23. Jeff Kunkle @kunklejr

×