I do not understand and do not know where to find this information

Asked

Viewed 34 times

0

const mongoose = require('mongoose')
const Schema = mongoose.Schema

let transactionSchema = new Schema({
  userId: mongoose.SchemaTypes.ObjectId,
  transactionDate: { type: Date, required: true },
  transactionType: { type: String, required: true },
  description: { type: String, required: true },
  charge: { type: Number, default: 0 },
  deposit: { type: Number, default: 0 },
  notes: { type: String, default: '' },
  createdOn: { type: Date, default: Date.now }
})

const Transaction = mongoose.model('Transaction', transactionSchema)

module.exports = Transaction

In the above code I understand that I am working on the model part because I have knowledge of MVC realize that I am monstando my database and ETC but what I do not realize is this excerpt:

const mongoose = require('mongoose')

It creates a constant ok but how does this require work ? Until where I realized it should fetch from my node_modules folder the files it needs to run correctly ? but how does it work exactly? know some documentation of this?

1 answer

1


If you want this level of detail, you better see the source code: module js.

And here the documentation in English: Node require

But simply put, if you just give the name of the module as in your example, the require will search for the module in all folders configured in module paths., or it can pass the path where the module is, so: require('/meus-modulos/mongoose');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.