fs-cheerio

3.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i fs-cheerio

Weekly Downloads

34

Version

3.0.0

License

BSD-2-Clause

Unpacked Size

4.35 kB

Total Files

5

Last publish

Collaborators

  • matthewp