/    Sign up×
Community /Pin to ProfileBookmark

Node Js file system

Hello i am using Node Js file system to make my code write the current date and time onto the “text.txt” file in my directory every 3sec in my directory……….
it only prints out one date…. any help? here is my code

var fs = require(‘fs’);
var http = require(‘http’);

function displayDate(){
Date();
};
var showDate = setInterval(displayDate,3000);

fs.writeFile(‘text.txt’,Date(), () => {
console.log(“The App is running…..”);
});

to post a comment

2 Comments(s)

Copy linkTweet thisAlerts:
@NachfolgerApr 02.2020 — @BENSONY63#1616857

Yes because you aren't calling it more than once... You are calling Date() every 3 seconds

``<i>
</i>setInterval(function() {
fs.writeFile("test.txt", Date(), function(err) {
if (err) { return false }
console.log("Running");
});
}, 3000);<i>
</i>
``


I don't know what the Date() function returns, but if it isn't a string/num you will run into issues with fs.writefile.
Copy linkTweet thisAlerts:
@BENSONY63authorApr 04.2020 — This runns perfectly bro, thanks so much.
×

Success!

Help @BENSONY63 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...