I was learning Node.js (even though I am not an expert in Javascript but I understand and write code on it). Now, trying to play with Node.js, I just got stuck in this code:
var fs = require('fs');
fs.readFile('/etc/passwd', function (err, data) {
if (err) throw err;
console.log(data);
});
Here is some of my confusions: The anonymous function is taking two arguments: err and data and inside the function err is for any error while reading the file which is thrown and data is the actual contents of the file.
- Well, how the function knows and differentiate between which one is error and which one is content of the file?
- Does it do like: the first argument is always an error and second argument is always the content data?
what err and data will have inside the function if I write like this
function(data, err) {} ?
This is just a simple function being passed just two arguments. How it works for some more arguments?
How inside the function, data is data and err is error?
For the above example, are err and data are pre-defined keywords (I doubt NO)?