Reputation: 2543
I'm using the Yeoman Generator Angular Fullstack and I'd like to reuse JS code from different directories within my server directory. I'm referencing the file that has the functions I want like:
var something = require('/.path');
I get the error: "Cannot find module" in my terminal.
I tried a number of variations of the path working through all of the levels from server level down to file level where the given functions are contained. I looked at a few tutorials:
http://www.sitepoint.com/understanding-module-exports-exports-node-js/ AND https://www.launchacademy.com/codecabulary/learn-javascript/node/modules
I clearly missed something. Each module of my nodejs has a controller with an exports.create
function. All of my code for each module is contained within my exports.create
function accept for other required modules. I have no problem requiring underscore or other libraries in my Node/Bower modules by the way.
To be as detailed as can be, I expected
var something = require('./directory/directory.controller.js');
Upvotes: 1
Views: 847
Reputation: 7912
var something = require('/.path');
The path you are using is likely incorrect. Probably you want to open the file called path.js
contained in the same folder of the file from which you are importing it. In order to do that, you should change the import as follows :
var something = require('./path');
./path
is a relative path where .
stands for current directory.
/.path
is an absolute path. In this case require is importing a hidden file in the root directory. I guess is not what you want.
Upvotes: 3