Answer the question
In order to leave comments, you need to log in
Module.exports does not produce what is required, how to fix it?
There is server.js:
var User = require('./user');
function run() {
var vasya = new User("Вася");
var petya = new User("Петя");
vasya.hello(petya);
}
if (module.parent) {
exports.run = run;
} else {
run();
}
var phrases = require('./ru');
function User(name){
this.name = name;
}
User.prototype.hello = function(who){
console.log(phrases.Hello + ", " + who.name);
};
console.log(module);
module.exports = User;
var vasya = new User("Vasya");
^
TypeError: User is not a constructor
at run (/home/daniil/MyProjects/nodeJS-learn/server.js:3:15)
at Object. (/home/daniil/MyProjects/nodeJS-learn/server.js:12:3)
at Module._compile (internal/modules/cjs/loader.js:707:30)
at Object.Module._extensions..js (internal /modules/cjs/loader.js:718:10)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
at Function.Module._load (internal/modules/cjs/loader.js:536:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
at startup (internal/bootstrap/node. js:303:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question