inControl
inControl

Reputation: 2324

Create object from require with Node.js

I am trying to create an object from the required file Account.js. Node.js displays an error on line var test = new account(); : Account is not defined. What am I doing wrong here?

// Account.js
module.exports = function Account() {
  console.log("THIS SHOULD WORK");
}

// app.js
require('./Account');
var test = new Account();

Upvotes: 0

Views: 254

Answers (1)

GilZ
GilZ

Reputation: 6477

Please note that require isn't like import or include. This is what you're missing:

// app.js
var Account = require('./Account');
var test = new Account();

Upvotes: 2

Related Questions