0

Suppose to have to file A.js and B.js: the path of this folder is:

A.js is in Project/Home and B.js is in Project

Project
    Home 
      A.js
    B.js

Suppose the code of B.js is something like this:

var elementi={name:'hi'};

    var esporta={};

    esporta.getAllElementi = elementi;

    module.exports = esporta;

The code of A.js is :

var elementi=require("../B.js");
//but when I call

var variable=elementi.getAllElementi;

the problem is the variable is null, Anyone can help me?

1
  • for me it works just fine. Commented Sep 7, 2017 at 8:33

1 Answer 1

1

I ran your code , was unable to reproduce the error.

Try replacing B.js with

var elementi={name:'hi'};

exports.getAllElementi = elementi;

and replace A.js with

var elementi=require(__dirname+"/../B.js");
var variable=elementi.getAllElementi;
console.log(variable);

If none of the above changes work , then try updating you Node js package.

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

Comments

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.