When I was running through this, I got the following error in my console referencing the fs.writeFile section.
mood=Excited
fs.js:144
throw new ERR_INVALID_CALLBACK(cb);
^
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
at maybeCallback (fs.js:144:9)
at Object.writeFile (fs.js:1325:14)
at IncomingMessage.<anonymous> (E:\Users\Christopher\Documents\GitHub\All_The_Feels\routes.js:30:10)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1221:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ERR_INVALID_CALLBACK'
}
In my troubleshooting, I added some error handling and it started working for me. I don't understand why adding error handling to that function helped but it allowed the file to be created.
Looking at Lisa's Github repo (linked below), my line 24 of routes.js now looks like:
fs.writeFile("user_mood.txt", mood, function (err) {
if (err) {
return console.log(err);
}
console.log("File saved successfully!");
});
Hopefully, this gets it to work for you too! I assume it's a copy/paste fail on my part and I am overlooking the error in my file but this worked for me.
Software engineer with a love for rock climbing. With a strong background in developer advocacy, I love creating tutorials & educational meetups to help developers get unstuck!
Location
Denver, Colorado
Work
Senior Developer Advocate @ Grafana | Full Stack Developer
Hi, this probably depends on the version of Node the post was written and version of Node you're using. The callback parameter is required since Node.js v10.0.0, see docs history where this is mentioned: nodejs.org/api/fs.html#fs_fs_write...
Software engineer with a love for rock climbing. With a strong background in developer advocacy, I love creating tutorials & educational meetups to help developers get unstuck!
Location
Denver, Colorado
Work
Senior Developer Advocate @ Grafana | Full Stack Developer
Malanius! Thank you for sharing your insights with everyone. One of the many things I love about the developer community is how generous and invested they are in other developers' growth. It feels really good to see readers helping other readers!! :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey Jornvm,
When I was running through this, I got the following error in my console referencing the fs.writeFile section.
In my troubleshooting, I added some error handling and it started working for me. I don't understand why adding error handling to that function helped but it allowed the file to be created.
Looking at Lisa's Github repo (linked below), my line 24 of routes.js now looks like:
LisaHJung / Node.js_Tutorial_Blog
Hopefully, this gets it to work for you too! I assume it's a copy/paste fail on my part and I am overlooking the error in my file but this worked for me.
Hey Christopher!
Thank you so much for taking the time to share your troubleshooting tips with everyone. I appreciate you!!
Hi, this probably depends on the version of Node the post was written and version of Node you're using. The callback parameter is required since Node.js v10.0.0, see docs history where this is mentioned: nodejs.org/api/fs.html#fs_fs_write...
Malanius! Thank you for sharing your insights with everyone. One of the many things I love about the developer community is how generous and invested they are in other developers' growth. It feels really good to see readers helping other readers!! :)