This is my user.js function. How do I create an instance of it in another file? I understand that this structure is a function that contains a class that contains functions inside it.

**user.js**

```
'use strict';
const {Sequelize} = require('sequelize');
const {
  Model
} = require('sequelize');

//This is a function that contains a class that contains functions

module.exports = (sequelize, DataTypes) => {
  class User extends Model {
     static init(sequelize) {
        super.init(
        {
          name: Sequelize.STRING,
        },
        {
          sequelize,
        });
        this.addHook('beforeSave', async (user) => {
          return user.id = uuid();
        });
        return this;
      }
      static associate(models) {
        // define association here
        User.hasMany(UserRole,
          {
            foreignKey: {
              field:'UserId',
              allowNull: false,
            },
          });
      }
  }

  User.init({
    Id: DataTypes.UUID,
    Name: DataTypes.STRING,
    UserName: DataTypes.STRING,
    Email: DataTypes.STRING,
    Password: DataTypes.STRING,
    PhoneNumber: DataTypes.STRING,
    MobileNumber: DataTypes.STRING,
    DateOfBirth: DataTypes.DATE,
    LockoutEnabled: DataTypes.BOOLEAN,
    LockoutEnd: DataTypes.DATE
  }, {
    sequelize,
    modelName: 'User',
  });

  return User;
};

```

In another file I have tried:

```
const {Sequelize, DataTypes} = require('sequelize');
const {sequelize} = require('../../database/connect');
const {userModel} = require('../../models/user');

function GetAll(UserName, Email){
  var option = new userModel;
  var option2 = new userModel(sequelize, DataTypes);
  return "1";
}

```

But both give me this error:

> 
> TypeError: userModel is not a constructor
> at Object.GetAll (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\data\userdata\userdata.js:8:16)
> at GetAll (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\areas\directory\controllers\usercontroller.js:6:27)
> at Layer.handle [as handle\_request] (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\layer.js:95:5)
> at next (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\route.js:137:13)
> at Route.dispatch (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\route.js:112:3)
> at Layer.handle [as handle\_request] (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\layer.js:95:5)
> at C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\index.js:281:22
> at Function.process\_params (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\index.js:341:12)
> at next (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\index.js:275:10)
> at Function.handle (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\index.js:174:3)
> 
> 
> 

Edit 1
------

If I remove new from them, I get the error: userModel is not a function.

Edit 2
------

Based on the recommendation by Luka Cerruti, I have changed my user.js like this:

```
module.exports.UserModel

```

And in the other file,

```
function GetAll(UserName, Email){
  console.log(UserModel);
  const user = UserModel(sequelize, DataTypes);
  console.log(user);
  return "1";
}

```

But a new error appeared:

> 
> TypeError: Cannot read properties of undefined (reading 'define')
> at Function.init (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\sequelize\lib\model.js:663:53)
> at Function.init (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\models\user.js:17:15)
> at module.exports.UserModel (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\models\user.js:41:8)
> at Object.GetAll (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\data\userdata\userdata.js:8:16)
> at GetAll (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\areas\directory\controllers\usercontroller.js:6:27)
> at Layer.handle [as handle\_request] (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\layer.js:95:5)
> at next (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node\_modules\express\lib\router\route.js:137:13)
> 
> 
> 
> ```
> at Route.dispatch (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node_modules\express\lib\router\route.js:112:3)
> at Layer.handle [as handle_request] (C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node_modules\express\lib\router\layer.js:95:5)
> at C:\Users\userone\Documents\Development\NodeJS\simple-express-project\node_modules\express\lib\router\index.js:281:22
> 
> ```
> 
>