write
‘write(string source, string content, string/Object parameters)’
The parameter object can contain :
- mode: Open Mode. A string made of ‘r’, ‘w’, ‘a/+’, ‘b’ characters.
- charset : An IANA, case insensitive, charset name.
If the source file can’t be opened then it will throw a ‘Unable to open file SOURCE’ and hang execution.
Examples
var fs = require('fs');
var path = 'output.txt';
var content = 'Hello World!';
fs.write(path, content, 'w');
phantom.exit();
fs.write(path, content, ‘a’); // will append to the end of an existing file or create a new file and write to it if path does not exist.
// If you are writing text files have a “\n” at the end of content if you want to append as a new line. Otherwise, it will keep adding text to the file without going to a new line.