0

I have some function that needs to be accessed from another file. But for some reason I can't do it.

 creatureScreenfunction (dir, jsonFile, pathToFile){
    let Mode = require('stat-mode'); 
    let temp; 
    fs.readdir(dir, function(err, items) 
.............................................
   
}

Here's what I tried

exports.creatureScreen = creatureScreen();

in second file

const index = require("../index.js");
1
  • You need to use module.exports and if they are in the same directory you will have to do require('./'something.js) Commented Sep 30, 2020 at 11:25

1 Answer 1

1

What you did here exports.creatureScreen = creatureScreen(); is named export. While importing it in some other file you need to do const {creatureScreen} = require("../index.js");.

Sign up to request clarification or add additional context in comments.

2 Comments

exports.creatureScreen = creatureScreen(); give me error
You should assign the reference, rather than executing it at the time of the assignment. What I mean is replace exports.creatureScreen = creatureScreen(); with exports.creatureScreen = creatureScreen;.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.