Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda