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

215
Views
NodeJS how to import conditionally?

The context is that I need to read the data from local memory instead of a database. I want to switch to a different memory object when I am testing. To achieve this, my plan is for my function that fetches the data to check the NODE_ENV, if it is "test", then import the data from directory A, else directory B.

However, doing if/else then import throws SyntaxError of unexpected identifier. Is there some way to do conditional import in NodeJS, or a more elegant way to achieve my purpose in general?

about 4 years ago · Juan Pablo Isaza
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!