Write data to the fixed line in the file:
nodejs when the need to use the fs module and the module path
The method used fs module readFileSync & writeFileSync ; readFileSync read file content, writeFileSync is a write to a file;
Realization of ideas:
1: reading the contents of the file and read the contents of the array is cut by a newline
2: (Inserts fixed to the table with the splice) the insertion of the contents of the array
3: The sub array into a string (using the method join, the join method is newline parameters), then the converted character string rewriting the original document
var FS = the require ( 'FS' ); var path = the require ( 'path' ); // write data to the fixed-line function writeFileToLine (value) { the let the basePath = path.resolve ( './' ); the let Data fs.readFileSync = (the basePath + '/ template.appcache', 'UTF8') Split (/ \ R & lt \ n-| \ n-| \ R & lt / GM);. // the first argument is the file name of readFileSync data.splice ( data.length -. 5, 0 , ... value); fs.writeFileSync ( './manifest.appcache', data.join ( '\ R & lt \ n-' )) }