Just try nodejs a few days.
Should i close somehow files after fs.readFile()
? And if yes how?
Should i null or something used and needless variables for better perfomance and memory safe?
Thanks.
close() Method. The fs. close() method is used to asynchronously close the given file descriptor thereby clearing the file that is associated with it. This will allow the file descriptor to be reused for other files.
readFile. Returns the contents of the file named filename. If encoding is specified then this function returns a string. Otherwise it returns a buffer.
var content; fs. readFile('./Index. html', function read(err, data) { if (err) { throw err; } content = data; }); console.
Syntax: fs.readFile( filename, encoding, callback_function ) Parameters: The method accept three parameters as mentioned above and described below: filename: It holds the name of the file to read or the entire path if stored at other location. encoding: It holds the encoding of file. Its default value is 'utf8'.
to close a file descriptor use this call
fs.close(fd, callback)
however since you're using fs.readFile
which reads the entire file - it deals with opening and closing file for you, so you don't need to close anything
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With