Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Putting all the imports in index file

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,
  });
};

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!