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

151
Views
Load a CJS module config inside another file

I'm trying to load a config inside a node module but I'm not sure which is a good practice to do it, I have this scenario:

A config my.config.js:

module.exports = {
  content: [
    './src/**/*.{tsx,ts}',
  ],
}

Then I have a module cli.mjs is supposed to load it:

import arg from 'arg'
import { readFile } from 'fs/promises'
import path from 'path'

let configPath = './my.config.js'

const args = arg({
  '--config': String,
  '-c': '--config',
})

if (args['--config']) {
  configPath = args['--config']
}

console.log(readFile(path.resolve(configPath), { encoding: 'utf8' }))

This will just return a simple string with my config inside, not a javascript object:

`
module.exports = {
  content: [
    './src/**/*.{tsx,ts}',
  ],
}
`

How should I load my config in the right way?

I've saw basically everyone use configs like that in TypeScript or CJS projects, but it's hard to me see how and where they parse these configs, probably I'm missing some basic information about this?

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!