How to handle badwords in Node.js ?

The bad-words module is used to handle the badwords by cleaning the given string. It is a JavaScript filter for bad words. This module searches for the profane words and replaces them with placeholder characters.

Feature of bad-words module:

  1. It is easy to get started and easy to use.
  2. It is widely used and popular filter for badwords.

Installation of bad-words module:

  1. You can visit the link to Install bad-words module. You can install this package by using this command.
    npm install bad-words
  2. After installing bad-words module you can check your request version in command prompt using the command.
    npm version bad-words
  3. After that, you can create a folder and add a file, for example index.js. To run this file you need to run the following command.
    node index.js

Filename: index.js

filter_none

edit
close

play_arrow

link
brightness_4
code

var Filter = require('bad-words');
  
var filter = new Filter();
  
filter.addWords('bad', 'dumb'); // Add your own words
  
console.log(filter.clean("Hello, I am not a bad ******"));
  
var new_filter = new Filter({ placeHolder: '$' });
  
console.log(new_filter.clean("Hello, I am not a bad ******"));

chevron_right


Steps to run the program:

  1. The project structure will look like this:
    project structure
  2. Make sure you have installed bad-words module using following command:
    npm install bad-words
  3. Run index.js file using below command:
    node index.js

    Output of above command

So this is how you can use a bad-words module that handles bad words by cleaning the given string.

My Personal Notes arrow_drop_up

To obtain a position of responsibility that utilizes my skills and keen to work in an environment where I can enrich my knowledge

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.