Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
What is the difference between "module.exports" and "exports.module" in java script

I have created a Model named 'Product' and the below code in there

const Sequelize = require('sequelize');

const sequelize = require('../util/database');

const Product = sequelize.define('product',{
    id: {
        type: Sequelize.INTEGER,
        autoincrement: true,
        allowNull: false,
        primaryKey: true
    },
    title: Sequelize.STRING,
    price: {
        type: Sequelize.DOUBLE,
        allowNull: false
    },
    imageUrl:{
        type: Sequelize.STRING,
        allowNull: true
    },
    description: {
        type: Sequelize.STRING,
        allowNull: true
    }
});

exports.module = Product;

I am getting the below error

Product.create is not a function

If I replace exports.module = Product; with module.exports = Product;, It is working good.

Can anyone clarify what is the difference between the two

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

module.exports is the property used to export values from a CommonJS module.

exports is a shorthand for module.exports.

exports.module is the same as module.exports.module which creates an value named module on the exported object.


So if you have:

module.exports = Product;

Then you would match it with:

const Product = require('./myModule');

But if you have:

exports.module = Product;

Then you would:

const myModule = require('./myModule');
const Product = myModule.module;

exports.module is, basically, a mistake and makes code confusing. Don't do that.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!