Answer the question
In order to leave comments, you need to log in
How to read number from Node.js file?
There is a file in which the number of records in the database. And I need to extract a number from a file: I'm trying like this:
fs.readFile("./files_to_help/QuoteNum.txt",{encoding:'utf8'},(err,data)=>{
var ret=0+data;
return ret;
});
undefined
I need the content to be returned in int format. How to do it?
Answer the question
In order to leave comments, you need to log in
fs.readFile('./files_to_help/QuoteNum.txt', {encoding:'utf8'}, (err, data) => {
console.log(parseInt(data.toString()));
});
let result = parseInt(fs.readFileSync('./files_to_help/QuoteNum.txt', {encoding: 'utf8'}));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question