Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fs-cheerio

matthewp69BSD-2-Clause3.0.0

file system tools to manipulate dom

cheerio, dom, fs

readme

Build Status npm version

fs-cheerio

DOM manipulation file system utilities. Combines Node's fs module with cheerio.

Install

npm install fs-cheerio --save

Usage

fs-cheerio allows you to read and write files to/from cheerio objects.

Note: While some of the below examples use async/await syntax, fs-cheerio will work with any Node version that supports Promises (or if you include a Promise polyfill).

readFile

Read from a file and create a cheerio object that can be manipulated. Returns a Promise that will resolve with the cheerio object.

const fsc = require("fs-cheerio");

fsc.readFile(__dirname + "/example.html").then(function($){
  // $ is a jquery/cheerio object that can be manipulated.
});

This works even better with async/await:

const fsc = require("fs-cheerio");

(async function(){
  let $ = await fsc.readFile(__dirname + "/example.html");
})();

writeFile

Write a cheerio object to a file. Returns a Promise that will resolve once the file has been written.

var fsc = require("fs-cheerio");

(async function(){

  let $ = await fsc.readFile(__dirname + "/example.html");
  $("#app").text("i changed this");

  await fsc.writeFile(__dirname + "/example.html", $);

})();

License

BSD 2 Clause