0

I'm new to blockchain and currently developing small application for educational purpose using solidity. I am using truffle framework and stuck at a point.

currently there is only one app.js file in the project, I want to create another js file and import that file in app.js just like classes in java.

for ex:- If I write register_user() function in example.js file, then how should I import that file in app.js so that I can call functions from example.js.

I've tried using 'module.exports = function(){};' but it throws error as Uncaught ReferenceError: module is ./example.js not defined

please help !!!

  • In app.js, you should do something like const example = require("./example.js");. Of course, this is under the assumption that both files are located in the same folder. If they are not, then you should use the relative path of example.js when you import it in app.js. – goodvibration Mar 2 at 11:46
  • I've already tried this but same error occurs Uncaught ReferenceError: module is ./example.js not defined – Shubham Naphade Mar 2 at 15:56
  • Then the two files are not in the same folder. In any case, you should post your code, if you're hoping to get any help with it. No one here is supposed to guess what you wrote! – goodvibration Mar 2 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.