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

223
Vistas
JSON file getting passed as JavaScript object in Express Node.js?

I am using the following line to import a JSON file in my code. However, instead of a config file, the jsonConfig variable is getting a JavaScript object and I can directly access, jsonConfig.children. Why is this happening? And how can I just import a JSON file instead of the object?

const jsonConfig = require('../../config/myconfig.json');
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

That's what's supposed to happen using your method, if you want to access the contents of the file as a text you should use fs

fs.readFile('../../config/myconfig.json', function read(err, data) {
    if (err) {
        throw err;
    }
    const content = data;

    // Invoke the next step here however you like
    console.log(content);   //Here you have the contents of your file

});
about 4 years ago · Juan Pablo Isaza Denunciar

0

JSON is stand for Javascript Object Notation, so a JSON is a valid object in javascript for that reason you are getting an object, you can access to the values using object notation, if want to get a string you can use JSON.stringify to convert your object into a string.

const jsonConfig = require('../../config/myconfig.json');
const jsonString = JSON.stringify(jsonConfig);
about 4 years ago · Juan Pablo Isaza Denunciar
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