I have created number of models(separate files) in my NodeJS Project. I am exporting all the files dynamically in single index.js file. Now when I require models folder and try to load the Model Intellisense is not be able to load that Model.
- Is there any solution to resolve this issue.
- Expected intellisene Path is
const {ModelController} = require('../models')
/models/index.js
'use strict';
const testFolder = './app/models';
const fs = require('fs');
const commons = require('../common');
const ExportsModel = {};
fs.readdirSync(testFolder).forEach((file) => {
const fileName = file.split('.')[0];
ExportsModel[commons.capitalizeFirstLetter(fileName) + 'Conrtroller'] = require(`./${fileName}`);
});
// console.info('ExportsModel', ExportsModel);
module.exports = ExportsModel;
/models/station.js
const mongoose = require('../configs/db.configs');
const Schema = mongoose.Schema;
const ModelSchema = new Schema(
{
name: { type: String, required: true },
stationId: { type: Schema.Types.ObjectId, ref: 'station', required: true },
description: { type: String, required: true },
},
{ timestamps: true }
);
module.exports = mongoose.model('charger', ModelSchema);
Thank you in advance