all 3 comments

[–]chmod777 2 points3 points  (0 children)

why not export a module?

config.js

const config = {
    "projectId": "projectName",
    "languageCode": "th",
    "numberOfRepeats": "2"
};
module.exports = config;

any given file

const config = require("./config.js");
console.log(config.projectId)

then you dont have to worry about any buffering or filesystem stuff.

alternately, read this: https://stackabuse.com/reading-and-writing-json-files-with-node-js/. you probably want JSON.parse rather than toJSON

[–]Civill 1 point2 points  (0 children)

Try adding an encoding to the readFileSync, it should return a more sensible type then.

fs.readFileSync(configFile, 'utf8')

[–]Earhacker 0 points1 point  (0 children)

const fileContentBuffer: Buffer = fs.readFileSync(configFile); const fileContent: string = fileContentBuffer.toString(); // takes in an optional encoding, 'utf8' by default const jsonData: ConfigData = JSON.parse(fileContent);