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

237
Views
How to require from required file?

I need to require bar from bar.js and foo from foo.js in each file.

How I can do it?

foo.js

const bar = require('./bar');
const foo = 'Hello';
console.log(`${foo} ${bar}!`);
module.exports = foo;

bar.js

const foo = require('./foo');
const bar = 'World';
console.log(`${foo} ${bar}!`);
module.exports = bar;

Main purpose is for have many to many GraphQL connection.

I want to require in rootQuery separate files with lets say postType.js and tagType.js. And I need to query posts from tags, and tags from posts.

Is it possible?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes this is possible node.js has built in mechanisms for handling just this sort circular require() calls. Please read the node documentation. https://nodejs.org/api/modules.html#modules_cycles

over 4 years ago · Santiago Trujillo 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!