Reputation:
I have a error "Callback must be a function" with this code
function saveCallback() {console.log("Sauvegarde du json")}
bot.login(TOKEN)
var test = '{"channelAlias":[]}'
setInterval(fs.writeFile('stockage.json',test,saveCallback), 300000)
Upvotes: 1
Views: 279
Reputation: 92
var fs = require('fs')
function saveCallback() {console.log("Sauvegarde du json")}
var test = '{"channelAlias":[]}'
setInterval(function(){fs.writeFile('stockage.json',test,saveCallback)}, 3000)
please see the difference
below will NOT GIVE ERROR
function willReturnFunction(){
return function(){
console.log("welcome")
}
}
setInterval(willReturnFunction(),1000)
below will GIVE ERROR (your case)
function willNotReturnFunction(){
//returning something other than funtion
// like fs.wrtiteFile function
return "some string"
}
setInterval(willNotReturnFunction(),1000)
I hope this helps! NAVIN
Upvotes: 0
Reputation: 381
const saveCallback = () => {
console.log(`Sauvegarde du json`)
}
bot.login(TOKEN)
const test = `{ "channelAlias": [] }`
setInterval(() => fs.writeFile(`./stockage.json`, test, saveCallback), 300000)
Upvotes: 0
Reputation: 5412
Try
function saveCallback() {console.log("Sauvegarde du json")}
bot.login(TOKEN)
var test = '{"channelAlias":[]}'
setInterval(() => {
fs.writeFile('stockage.json',test,saveCallback)
}, 300000)
setInterval
's signature is setInterval(callbackFUNCTION, time)
Upvotes: 1