nodejs file related modules

--fs
require('fs')

fs.readFile(filename, [encoding], [callback(err,data)])

When content encoding is not set, it will be output in buffer format

Receive parameters:

filename file path

options option object, including encoding, encoding format, this item is optional.

callback callback, passing 2 parameters exception err and file content data

var fs = require('fs');
fs.readFile('2.js', 'utf-8', function (err, data) {
    if (err) {
        console.log(err);
    } else {
        console.log(data);
    }
});

--path

require('path')

path.sep

path.extname()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325293418&siteId=291194637