Skip to content
Related Articles

Related Articles

Improve Article

How to handle badwords in Node.js ?

  • Last Updated : 03 Jun, 2020

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




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 ******"));

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
Recommended Articles
Page :