I have code from a non-FCC tutorial, a simple module and a very small program that uses the module, that supposedly works.
(In order to figure out what is needed to solve one of the Start a Nodejs Server FCC challenges, this is a tutorial I turned to to find out more about how nodejs ticks).
However the tutorial is not explicit about where to put the two files in node.js and get them to talk to each other.
For example, I put both the module, called “mulitply.js” and the code that uses it, called “test.js” in the same directory (side by side in the same file). I ran node test.js and got the “Error: Cannot find module” error.
I then created a folder in that same directoy called “modules” and put “mulitply.js” in that folder, then ran test.js, and go the same error (“Error: Cannot find module”)
What am I missing? Why is it that I am getting this error? I am fairly certain the code is correct (because I did not write it!)
multiply.js:
// require any modules
module.exports = {
multiply: function (val1, val2, callback){
var returnedValue = val1 * val2;
callback(null, nonPublic() + returnedValue);
}
};
function nonPublic(){
return 'Result: ';
}
test.js:
var mod = require('./module');
console.log(mod.nonPublic());
mod.multiply(5, 10, function(err, result){
console.log(result);
});
I was using this tutorial: https://mrvautin.com/writing-your-first-node-js-module/