Putting all the imports in index file

Viewed 71

I'm working on a node/express project and I'm wondering if it's better to put all the imports of the dependencies in the index file of a controller and then pass them as parameters to the function or each function should have its required dependencies - screenshot of controller's files

import passport from 'passport';
import jwt from 'jsonwebtoken';
import crypto from 'crypto';
import util from 'util';
import httpStatusCodes from '../../utils/httpStatusCodes.js';
import * as login from './login.controller.js';
import logout from './logout.controller.js';
import * as reserPasswordController from './reset-password.controller.js';
import { ErrorHandler } from '../../utils/errorsHandler.js';
import responseHandler from '../../utils/responseHandler.js';
import signupUser from './signup.controller.js';
import addressService from '../../services/address.services.js';
import * as emailVerificationController from './email-verification.controller.js';
import generateCode from '../../utils/codeGenerator.js';
import sendMail from '../../utils/sendEmail.js';
import verifyEmailTemplate from '../../utils/verifyEmailTemplate.js';
import crudHandler from '../../services/crudHandler.js';

const randomBytesAsync = util.promisify(crypto.randomBytes);

const signin = (req, res, next) => {
  const secret = process.env.TOKEN_SECRET;
  login.login({
    req,
    res,
    next,
    passport,
    ErrorHandler,
    httpStatusCodes,
    responseHandler,
    jwt,
    secret,
  });
};

1 Answers

I think it's better to put all the dependencies in the index file. However, I'm not 100% sure of that, and I don't think it really matters, just whichever you feel like doing and works out best for you.

Related