Quantcast
Channel: Forum Pasja Informatyki - Najnowsze pytania bez odpowiedzi
Viewing all articles
Browse latest Browse all 22017

Odczytanie pliku tekstowego w nodejs

$
0
0

Witam, chciałbym zrobić, żeby w pliku count.txt była cyfra "0" po uruchomieniu skryptu nodejs zwiększała się o jeden. Tutaj jest mój kod:

 

var fs = require('fs');
fs.readFile("count.txt", function(error, data) {
    console.log("Wartosc: " + data);
    var count = data;
 });

fs.writeFile("count.txt", count++, function(err) {
     if(err) {
         return console.log(err);
    }
    console.log("Wartosc zwiekszono o jeden!");
});

fs.readFile("count.txt", function(error, data) {
    console.log("Obecna wartosc: " + count);
});

Wydaje mi się, że zmienna count jest problemem, ale nie wiem jak przenieść te dane dalej. 


Viewing all articles
Browse latest Browse all 22017

Trending Articles