Monday 1 May 2017

module.export - Person is not a constructor

I'm following a tutorial about Node.JS custom modules. I created the file Person.js:

var EventEmitter = require('events').EventEmitter;
var util = require('util');

var Person = function(name) {
  this.name = name;
}

util.inherits(Person, EventEmitter);

module.exports = Person;

Next, I created the file custom-module.js:

var Person = require('./lib/Person');

var ben = new Person("Benjamin Franklin");

Then, when I run node custom-module.js I get the following error message:

TypeError: Person is not a constructor

What am I doing wrong?



via user2671169

No comments:

Post a Comment