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

228
Views
¿El archivo JSON se pasa como objeto JavaScript en Express Node.js?

Estoy usando la siguiente línea para importar un archivo JSON en mi código. Sin embargo, en lugar de un archivo de configuración, la variable jsonConfig obtiene un objeto JavaScript y puedo acceder directamente a jsonConfig.children . ¿Por qué está pasando esto? ¿Y cómo puedo importar un archivo JSON en lugar del objeto?

 const jsonConfig = require('../../config/myconfig.json');
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Eso es lo que se supone que sucederá con su método, si desea acceder al contenido del archivo como texto, debe usar 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 Report

0

JSON significa Notación de objetos de Javascript, por lo que un JSON es un objeto válido en JavaScript, por esa razón está obteniendo un objeto, puede acceder a los valores usando la notación de objetos, si desea obtener una cadena, puede usar JSON.stringify para convertir su objeto en una cadena.

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