A fantastic explanation.

On Tuesday, November 27, 2012 3:17:14 AM UTC+11, Charles Care wrote:
>
> Hi Dave,
>
> The callback-based APIs follow a convention where the first positional 
> parameter is for error information. You're asking the Node 'fs' library to 
> read 'file1.txt'. If the read is successful, then the 2nd param ('data') 
> will contain a representation of the file's contents, and the 1st param 
> will be null. Alternatively, if an error occurs, then the err parameter 
> will have a value representing the error, and the 2nd param will be either 
> null or undefined. 
>
> The parameter names are a convention: you could call them 'apple' and 
> 'orange', but that would really make your code hard to maintain!
>
> Hope that helps,
>
> Charles
>
> On 26 November 2012 15:50, Dave Johnson <[email protected]<javascript:>
> > wrote:
>
>> Hello and I apologise if this is a stupid question but I am reading up on 
>> Callbacks in node.js and wanted to ask something about it. 
>>  
>> Example code:
>>  
>> fs.readFile('file1.txt', 'utf8', function (err, data) {
>>       if (err) throw err;
>>       console.log('File 1 read!');
>>   });
>>  
>> I just dont know what the parameters *err* & *data* are, is this 
>> something that the node.js engine resolves internally? Hope I am making 
>> sense, in other coding you would create these variables and then pass them 
>> to a method.
>>  
>> Thanks,
>>  
>> Dave Johnson
>>
>>
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to