Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does require('../') mean? [duplicate]

Tags:

node.js

Possible Duplicate:
Node.js - require empty path

What does require('../') mean in the context of node.js? Example code here.

like image 857
Randomblue Avatar asked Dec 03 '11 00:12

Randomblue


People also ask

Is it better to use require or import?

One of the major differences between require() and import() is that require() can be called from anywhere inside the program whereas import() cannot be called conditionally, it always runs at the beginning of the file. To use the require() statement, a module must be saved with .

What is require () in JavaScript?

“Require” is built-in with NodeJS require is typically used with NodeJS to read and execute CommonJS modules. These modules can be either built-in modules like http or custom-written modules. With require , you can include them in your JavaScript files and use their functions and variables. // built-in moduels.

What does require stack mean?

Require Stack is a wrapper around require method, which makes it easier to get syntax error with proper error stack when wrapping require call under try/catch block.


1 Answers

A folder can be used as a module if the folder contains any of the following files (in lookup order): package.json, index.js, or index.node.

In this case, the folder has a package.json file that, among some other things, states that the main file of the module is the index.js file in the same directory. So the require('../') call you asked about could be changed to require('../index.js').

See Node.js Documentation - Folders as Modules for more information.

like image 181
Felix Loether Avatar answered Oct 03 '22 18:10

Felix Loether