Las Carpetas Usadas Como Módulos

It is convenient to organize programs and libraries into self-contained directories, and then provide a single entry point to that library.

There are a few ways in which a folder may be passed to require() as an argument.

  1. The first is to create a package.json file in the root of the folder, which specifies a main module. An example package.json file might look like this:

    { "name" : "some-library",
      "main" : "./lib/some-library.js" }

    If this was in a folder at ./some-library, then require('./some-library') would attempt to load ./some-library/lib/some-library.js.

    This is the extent of Node's awareness of package.json files.

  2. If there is no package.json file present in the directory, then node will attempt to load an index.js or index.node file out of that directory.

    For example, if there was no package.json file in the above example, then require('./some-library') would attempt to load:


Casiano Rodriguez León 2015-06-18