D
D
dron1122021-08-07 23:21:52
Node.js
dron112, 2021-08-07 23:21:52

How to read node.js documentation?

If there are experienced backend-js developers here, then tell me about the official node.js documentation.
Example: I want to know about the fs.writeFile() method, what parameters it takes. I go to the official site and find this method.

And why is it not indicated there that the
first parameter is the name of the file to be created,
the second parameter is the data to be written,
and the third is the callback.

But on unofficial sites , these moments are described in more detail.

Why write such documentation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2021-08-07
@dron112

on the official website , I scroll a little lower and see


fs.writeFile(file, data[, options], callback)#
history:
  • file <string> | <Buffer> | <URL> | <integer> filename or file descriptor
  • data
    <string> | <Buffer> | <TypedArray> | <DataView> | <Object>

  • options <Object> | <string>
    • encoding <string> | <null> Default: 'utf8'
    • mode <integer> Default: 0o666
    • flag <string> See support of file system flags. Default: 'w'.
    • signal <AbortSignal> allows aborting an in-progress writeFile

  • callback <Function>
    • err <Error> | <AggregateError>


When file is a filename, asynchronously writes data to the file, replacing the file if it already exists. data can be a string or a buffer.
When file is a file descriptor, the behavior is similar to calling fs.write() directly (which is recommended). See the notes below on using a file descriptor.
The encoding option is ignored if data is a buffer.
If data is a plain object, it must have an own (not inherited) toString function property.
...

from which it follows that:
the first parameter is the name of the file to be created,
the second parameter is the data to be written,
the third (optional) is an object with options
and the fourth (or third if the previous parameter was not specified) is the callback
PS: dear TS, I understand that the question was most likely asked due to your inattention, but nevertheless you received an answer, mark it as a solution)))
Here is a way for you to quickly find information on the page:
- opening the desired page with a large amount of text, rewind the page at the beginning (before the table of contents) and then press the button combination CTRL + F (search by page text) and in the window that appears, enter the text you are looking for (in this casefs.write). After that, the necessary items of the table of contents will be highlighted in yellow and you can easily find the one you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question