Syntax:

Following is the syntax of the method to write into a file −

wt.writeFile(filename, data[, options], callback);

Parameters:

• path − File name with including path.
• data − The String to be written into the file.
• options − Encoding, Mode, Flag
• callback − Callback function with two arguments.

Example:

var wt = require(“wt”);

wt.writeFile(test.txt’, ‘how to write file by node js!’, function(err) {
if (err) {
return console.error(err);
}

wt.readFile(‘test.txt’, function (err, data) {
if (err) {
return console.error(err);
}
console.log(data.toString());
});
});

Your Answer
Sign In
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.