Writing npm packages

If you create some code that would be useful to others, you can distribute it as an npm package. To demonstrate this, we'll implement some slightly more complex functionality.

Note

You can find the example code for this section at https://github.com/NodeJsForDevelopers/autotoc. Note that, unlike previous chapters, there is not one per commit per heading. The listings in the rest of this section match the final version of the code.

We're going to implement a tool for generating a table of contents (ToC) by crawling a website. To help with this, we'll make use of a few other npm packages:

  • request provides an API for making HTTP requests, which is higher-level and much simpler to use than the build in the Node.js http module
  • cheerio ...

Get Learning Node.js for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.