0

I want to see the Code that gets executed when Customer.create gets called but I don't know how I can analyse the code of the mongoose module. So far i understand that require('mongoose) will lookup in the node_modules folder for the mongoose folder. This mongoose Folder has a package.json that reference with a main key to an index.js file inside the mongoose folder.

This is the index.js file:

'use strict';

module.exports = require('./lib/');

require will look in the ./lib/ folder for an index.js. This is a big file and i don't know how i can proceed in order to understand what the create function is doing. How would an expert check what the create function is doing exactly?

//app.js
require("dotenv").config();
const mongoose = require('mongoose');
const Customer = require('./models/Customer');

const start = async () => {
  const db = await mongoose.connect(process.env.MONGO_URI);
  try {
    const customer = await Customer.create([{ firstName: "john" }], { session: session });
  } catch (error) {
    console.error(error);
  }
};

start();
//Customer.js
const mongoose = require('mongoose');
const CustomerSchema = new mongoose.Schema({ firstName: { type: String } });

module.exports = mongoose.model('Customer', CustomerSchema);
swftowu69
  • 123
  • 1
  • 9
  • 1
    I would use a debugger to step through the code. – jabaa Nov 13 '21 at 20:51
  • 1
    Does this answer your question? [How do I debug Node.js applications?](https://stackoverflow.com/questions/1911015/how-do-i-debug-node-js-applications) – banyudu Nov 16 '21 at 02:22
  • Hey, thanks for the answers. I use now a debugger in visual studio code and it works great. – swftowu69 Nov 16 '21 at 11:52

0 Answers0