Reputation: 2461
I am new with Nodejs. I want to export from file1.js file to file2.js.
file1.js is located in root-directory and file2.js is in some sub-directory. When I am calling it as require('/file1')
in file2.js its saying like Uncaught Error: Module name "/file1" has not been loaded yet for context: _. Use require([])
. Any help? Sorry if this is silly, but I am new.
Upvotes: 1
Views: 686
Reputation: 18900
var Logger = require('./logger');
Requires the module you have written, in a file called logger.js stored in the same directory your code was launched from.(not necessarily the same directory your code is stored in).
var someOtherModule = require('../../someOtherModule');
Requires someOtherModule.js file two directories back from where the node process is launched.
var someOtherModule = require('./subDir/someOtherModule');
Requires someOtherModule.js file, sotred in subDir. subDir is a directory located at the level of where the node process was launched.
var awssum = require('awssum');
Requires a module installed via NPM, in the node_modules directory from which the process was launched, or any globally installed node modules. For versioning, the node_modules directory takes precedence.
Upvotes: 1