Possible Duplicate:
Node.js - require empty path
What does require('../')
mean in the context of node.js? Example code here.
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 .
“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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With