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

192
Views
How can I import all the function from other file to current file?

I have one file containing many functions. Similar to below,

export const func1 = () => {
}

export const func2 = () => {
}

export const func3 = () => {
}

export const func4 = () => {
}

Now I want to use all this function in another file.

Method 1 is import {func1, func2, func3, func4} from 'path'.
Method 2 (which I don't want to use) is import * as access from 'path'

Method 1 approach is what I am using right now. But when func file gets bigger, this will not be readable. So, how to use the functions without creating aliases and simply func1() and not access.func1() ?

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

0

You should really make up your mind between the two as they are the most readable and clean solutions.

First option can be made more readable with:

import {
  func1,
  func2,
  func3,
  func4
} from 'path';

Nevertheless, if you really want an alternative syntax without having to list the exports, it is technically possible to load all the exported properties into the global object through:

Object.assign(globalThis, require('path'))

However, I would highly advise against this as it'll make your code very difficult to maintain. Global variables are painful enough, but unknown global variables coming from another file will be a nightmare. Use at your own risk.

about 4 years ago · Juan Pablo Isaza Report

0

You can import with your Method 2 and then can use object destructuring on the access object like this and use them directly.

import * as access from 'path';

const {func1, func2, func3, func4} = access;

func1();
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!