fc

fs-cheerio

Read and write files to/from cheerio objects.

Showing:

Popularity

Downloads/wk

5

GitHub Stars

14

Maintenance

Last Commit

2yrs ago

Contributors

3

Package

Dependencies

1

License

BSD-2-Clause

Type Definitions

Tree-Shakeable

No?

Categories

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial