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:
- It is easy to get started and easy to use.
- It is widely used and popular filter for badwords.
Installation of bad-words module:
- You can visit the link to Install bad-words module. You can install this package by using this command.
npm install bad-words
- After installing bad-words module you can check your request version in command prompt using the command.
npm version bad-words
- 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:
- The project structure will look like this:
- Make sure you have installed bad-words module using following command:
npm install bad-words
- Run index.js file using below command:
node index.js
So this is how you can use a bad-words module that handles bad words by cleaning the given string.
Please Login to comment...