Nodejs Module--FS Module WriteFile write file

Source: Internet
Author: User

WriteFile Writing Files

Writes content to a file using Fs.writefile (Filename,data,[options],callback).

Parameter description:

    • FileName String filename
    • Data String| Buffer
    • Option Object
      • Encoding String | NULL default= ' Utf-8 '
      • Mode number default=438 (aka 0666 in octal)
      • Flag Stringdefault= ' W '
    • Callback Function

Example:

After writing the file:

Code:

Readfile.js

var fs = require (' FS '); Introduce FS module//write file contents (if file does not exist will create a file)//pass append parameter {' flag ': ' A '}fs.writefile ('./try4.txt ', ' HelloWorld ', {' flag ': ' A '}, func tion (err) {    if (err) {        throw err;    }    Console.log (' Hello. ');    After the write succeeds read the test    fs.readfile ('./try4.txt ', ' utf-8 ', function (err, data) {        if (err) {            throw err;        }        Console.log (data);})    ;

Output:

2017-10-20 17:03:19

Nodejs Module--FS Module WriteFile write file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.