> ### [`fs.createWriteStream(path[,options])`](
[To see links please register here]
)
>
> `options` may also include a `start` option to allow writing data at some position past the beginning of the file. Modifying a file rather than replacing it may require a `flags` mode of `r+` rather than the default mode `w`. The encoding can be any one of those accepted by [Buffer](
[To see links please register here]
).
>
> If `autoClose` is set to true (default behavior) on `'error'` or `'finish'` the file descriptor will be closed automatically. If `autoClose` is false, then the file descriptor won't be closed, even if there's an error. It is the application's responsibility to close it and make sure there's no file descriptor leak.
>
> Like [ReadStream](
[To see links please register here]
), if `fd` is specified, [WriteStream](
[To see links please register here]
) will ignore the `path` argument and will use the specified file descriptor. This means that no `'open'` event will be emitted. `fd` should be blocking; non-blocking `fd`s should be passed to [net.Socket](
[To see links please register here]
).
>
> If `options` is a string, then it specifies the encoding.
After, reading this long article. You should understand how it works.
So, here's an example of `createWriteStream()`.
/* The fs.createWriteStream() returns an (WritableStream {aka} internal.Writeable) and we want the encoding as 'utf'-8 */
/* The WriteableStream has the method write() */
fs.createWriteStream('out.txt', 'utf-8')
.write('hello world');