Creating a Node.js Packaged Module

To create a Node.js Packaged Module, you need to create the functionality in JavaScript, define the package using a package.json file, and then either publish it to the registry or package it for local use.

The following steps take you through the process of building a Node.js Packaged Module, using a module called censorify that will accept text and replace certain words with asterisks:

1. Create a project folder named .../censorify. This will be the root of the package.

2. Inside that folder, create a file named censortext.js.

3. Add the code from Listing 3.1 to censortext.js. Most of the code is just basic JavaScript, but note that lines 18–20 export the functions censor(), addCensoredWord(), and getCensoredWords() ...

Get Node.js, MongoDB, and AngularJS Web Development 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.