LearningNodeJS icon indicating copy to clipboard operation
LearningNodeJS copied to clipboard

Learning NodeJS, Chapter 8, Page 177

Open ghost opened this issue 8 years ago • 1 comments

The following 2 lines (page 177): var db = require('./db.js'); var albums = db.albums;

I see the genius in it... I don't fully grasp it...;

It seems, the 2nd time I request the module, I have access to the collections...;

ghost avatar Jun 13 '17 05:06 ghost

Hi!

I'm not 100% sure what you're asking?

--> When you require a module, that module is assigned to the variable you declared, i.e. db. You can then access anything exported from that module just like a var on an object, like a function or a collection, such as albums here.

marcwan avatar Sep 27 '17 13:09 marcwan