-1
insira o código aqui
Version of Node 10.5.3
I am trying to export a class, to use it in another file. I have seen several examples on the internet and none of them helped me.
Below is the class I want to export.
class Retangulo {
constructor(altura, largura) {
this.altura = altura; this.largura = largura;
}
get area() {
return this.calculaArea()
}
calculaArea() {
return this.altura * this.largura;
}
}
module.exports = Retangulo;
And the file where I’m trying to use the Rectangular class
const Retangulo = require('./teste.js');
var a = new Retangulo(10,10)
console.log(a.area);
You can fix this error using "module.Exports = new Rectangle();", but then it returns an already instantiated object, and I want direct instantiation in the teste1.js file. I’m using the consign to load my routes.
This code is in my server.js file
consign().include('models').into(app);
Someone can help me with that. In case it’s not very clear, and just ask that I clarify.
What version of Node.js are you using? Find out by running
node --version
in your terminal. Post also your complete code in text form, image.– Luiz Felipe
I suggest you read carefully how to make a good question here in the community.
– user148754
For
log
error, the problem is in the libraryconsign
. You need to post the full code so we can help you.– Luiz Felipe
I am trying to tidy up the issue. I ask apologies for the lack of organization of the questions, and I appreciate the tips.
– Samuel Ribeiro