Can commonjs write js files into require without export?

for the node+mongoose project I wrote, the code that defines the mongoose module is stored in the models folder. If I write a module.exports= export, node will report an error.

here is a model

const mongoose = require("mongoose")
const Schema = mongoose.Schema
const mongoosePaginate = require("mongoose-paginate")

// 
/**
*fieldType:
 (input)text
 textarea
 (input)number
 (input)email
 (input)date
  (input)radio
 (input)checkbox
 select
 table
 (input)file(url)
*/
const FormModelSchema = new Schema({
    formName: String,
    instruction: String,
    userName: String,
    updateUserName: String,
    userId:String,
    updateUserId: String,
    createAt: {type: Date, default: Date.now},
    updateAt: {type: Date, default: Date.now},
    formFields: [{
        displayName: String,
        // fieldName:String,
        fieldType: String,
        placeholder:String,
        isRequired:{type: Boolean, default: false},
        value:String,
        column:String,
        fieldOptions:[{
            displayText:String,
        }],
        fieldOrder:Number
        // or   /
        // maxSize:String, 
    }]
})
// Defines a pre hook for the document.
FormModelSchema.pre("save", function(next) {
    if (this.isNew) {
        this.createAt = this.   updateAt = Date.now()
    }
    else {
        this.updateAt = Date.now()
    }
    next()
})
FormModelSchema.plugin(mongoosePaginate)

var FormModel=mongoose.model("FormModel", FormModelSchema)
module.exports=FormModel

this is an error message:

clipboard.png

app.jsrequire modelsjs

:
modelformModel

model:


:

clipboard.png

Mar.10,2021

if you haven't used Mongoose, you can't see it at a glance, and you don't know if you don't debug it. However, not exporting is tantamount to not executing, so it is normal not to report an error. The subject should try to get rid of the mistakes and read the document carefully. There are no mistakes that cannot be eliminated, and only when you get rid of them in a down-to-earth way can you have a chance to get promoted.


on the premise of not exporting, the structure and definition of another model code and the method of saving are almost the same as this, but the other one can store data normally, and this file cannot be saved. Every time the interface for storing data is called, it is said that formModel does not exist. I found the reason because the variable name conflicted with this when I created the FormModel instance.

Menu