node.js error when using: npm run dev, TypeError: require(…) is not a function

im working on my first project, added a database and im trying to make a login page.

while i try to run it using npm run dev. it gives me an error exact error is at the bottom

I dont know what causes this and how i can fix this can somebody help please?

the database structure looks like this:

The folder structure of my app looks like this:

my config/database.js is this:

const { Sequelize } = require('sequelize');

const sequelize = new Sequelize('dfddatabase', 'root', 'Password', {
  host: 'localhost',
  dialect: 'mariadb',
  logging: false
});

const connectDb = async () => {
    try {
      await sequelize.authenticate();
      console.log('Connection has been established successfully.');
    } catch (error) {
      console.error('Unable to connect to the database:', error);
    }
  };

module.exports = { sequelize, connectDb };

The models/index.js:

const { Sequelize, DataTypes } = require('sequelize');
const sequelize = new Sequelize('mysql://user:password@localhost:3306/database_name', {
  dialect: 'mariadb',
});

// Import models
const User = require('./user')(sequelize, DataTypes);
const CsvFile = require('./csvfile')(sequelize, DataTypes);
const PasswordReset = require('./passwordreset')(sequelize, DataTypes);
const Setting = require('./setting')(sequelize, DataTypes);
const ScharnierType = require('./scharniertype')(sequelize, DataTypes);
const DeurType = require('./deurtype')(sequelize, DataTypes);

// Define associations
User.hasMany(CsvFile, { foreignKey: 'user_id' });
CsvFile.belongsTo(User, { foreignKey: 'user_id' });

User.hasOne(Setting, { foreignKey: 'user_id' });
Setting.belongsTo(User, { foreignKey: 'user_id' });

Setting.belongsToMany(ScharnierType, { through: 'settings_scharniertypes' });
ScharnierType.belongsToMany(Setting, { through: 'settings_scharniertypes' });

Setting.belongsToMany(DeurType, { through: 'settings_deurtypes' });
DeurType.belongsToMany(Setting, { through: 'settings_deurtypes' });

module.exports = {
  sequelize,
  Sequelize,
  User,
  CsvFile,
  PasswordReset,
  Setting,
  ScharnierType,
  DeurType
};


sequelize.sync({ force: true }).then(() => {
    console.log("Database & tables created!");
  });

the modules of user.js:

module.exports = (sequelize, DataTypes) => {
    const User = sequelize.define('User', {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },
      email: {
        type: DataTypes.STRING,
        unique: true,
        allowNull: false,
      },
      password: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      createdAt: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW,
      },
      updatedAt: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW,
      },
    }, {
      tableName: 'users'
    });
    return User;
  };
  

my routes/index.js:

const express = require('express');
const router = express.Router();

// Index Page
router.get('/', (req, res) => res.render('index', { title: 'Home' }));

module.exports = router;

my app.js:

const express = require('express');
const session = require('express-session');
const flash = require('connect-flash');
const passport = require('passport');
const path = require('path');
const { connectDb } = require('./models');
const sequelize = require('./config/database');

const app = express();

app.listen(PORT, () => {
  console.log(`Server running on http://localhost:4000`);
});


// Passport Config
require('./config/passport')(passport);

// EJS
app.set('view engine', 'ejs');

// Static Files
app.use(express.static(path.join(__dirname, 'public')));

// Bodyparser
app.use(express.urlencoded({ extended: false }));

// Express session
app.use(
  session({
    secret: 'secret',
    resave: true,
    saveUninitialized: true
  })
);

// Passport middleware
app.use(passport.initialize());
app.use(passport.session());

// Connect flash
app.use(flash());

// Global variables
app.use((req, res, next) => {
  res.locals.success_msg = req.flash('success_msg');
  res.locals.error_msg = req.flash('error_msg');
  res.locals.error = req.flash('error');
  res.locals.user = req.user || null;
  next();
});

// Routes
app.use('/', require('./routes/index'));
app.use('/auth', require('./routes/auth'));
app.use('/password', require('./routes/password'));

const PORT = process.env.PORT || 5000;

connectDb().then(() => {
  app.listen(PORT, console.log(`Server started on port ${PORT}`));
});

my package.json:

{
  "name": "loginapp",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon app.js",
    "start": "node app.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "connect-flash": "^0.1.1",
    "dotenv": "^16.4.5",
    "ejs": "^3.1.10",
    "express": "^4.19.2",
    "express-session": "^1.18.0",
    "jsonwebtoken": "^9.0.2",
    "mariadb": "^3.3.1",
    "mysql2": "^3.10.1",
    "nodemailer": "^6.9.14",
    "nodemailer.js": "^0.0.2-security",
    "passport": "^0.7.0",
    "passport-local": "^1.0.0",
    "sequelize": "^6.37.3"
  }
}

and in my console cmd i get this:


C:UsersRobbeDownloadsLoginApp>npm run dev

> [email protected] dev
> nodemon app.js

[nodemon] 3.1.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node app.js`
C:UsersDelsoirRobbeDownloadsLoginAppmodelsindex.js:7
const User = require('./user')(sequelize, DataTypes);
                              ^

TypeError: require(...) is not a function
    at Object.<anonymous> (C:UsersDelsoirRobbeDownloadsLoginAppmodelsindex.js:7:31)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:UsersDelsoirRobbeDownloadsLoginAppapp.js:6:23)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)

Node.js v20.13.1
[nodemon] app crashed - waiting for file changes before starting...

if somebody can help or need any more info, i would be very greatful!!

i tried replacing my models, i tried using diffrent localhost things, changed my database password, installed npm packages again, but it didnt change anything..

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật