What happens if we pass the directory location to Node.js require function?

I cloned an Express.js repo containing an example folder with various uses for Express.js. I opened the Hello World example, and the code started on the next line

var express = require('../../');

I understand the rest of the code in this file, but does the line above go along my head? I know that the function is requireused to include the JS module in your project, and one should pass the module name as an argument to the function require(), but in the case of the above statement we pass the directory, what will it do?

+4
source share
2 answers

index.js, .

:

enter image description here

, yourFile.js

var something = require('../../');

index.js.

, - :

var something = require('../../index');

( .js, )

var something = require('../../index.js');

, index.js .

nodejs.org, :

package.json, Node.js index.js index.node . , package.json , ('./some-library') :

./some-library/index.js

./-/index.node

+5

index.js, .

+2

Source: https://habr.com/ru/post/1608856/


All Articles