Keep it Clean: 'bad-words' npm Package for Content Filtering.

Web DevelopmentJavaScript

3 Minute Read

Forbidden Sign

We might’ve encountered at least one offensive comment or come across that one peculiar username that leaves us feeling disgusted (eww) or frustrated (ugh). In today’s instantly evolving digital era, content moderation and filtering are essential to find the middle ground for secure digital space and freedom of expression. If you are a developer and you want to steer away these "bad words" from your application radius using a npm package, use bad-words indeed.

The bad-words npm package is a popular JavaScript library that enables developers to filter and censor offensive words within their applications. It has garnered a strong community support due to its effectiveness and ease of use.

It allows automatic scanning and filtering of text input such as comments, articles, usernames, messages etc. from users.

This package has an extensive list of predefined offensive words & phrases that are generally considered inappropriate or offensive. This list gets updated based on evolving language trends. Beyond that,the package is highly customizable, allowing us to add our own words to the list, specify the replacement characters, and adjust filtering behaviors to align with our application's desired needs.

Here’s a sneak peak to the usage of bad-words package in JavaScript:

Installation & Setup

Install the package by running the following command in your terminal:

npm install bad-words --save

Import the package to your JavaScript file & initialize it:

const Filter = require('bad-words'); const filter = new Filter();


Below is a list of parameters and methods that you can select to tailor to your specific requirements:

  • list: To view the current list of bad words.
  • isProfane: To check if the content contains any offensive words.
  • clean: To replace the filtered offensive words with asterisks by default.
  • Placeholder Overrides: To change the default replacement character asterisk with any other symbol of your choice.
  • Regex Overrides: To specify custom regular expressions to target specific words or phrases for replacement or censoring.
  • replaceWord: To replace a word with placeHolder characters.
  • addWords: To add custom words to the blacklist.
  • removeWords: To remove words from the blacklist.

Additionally, check out the source code on the official GitHub repository of this package for more in-depth insights. As you implement this “bad- words” package, remember the middle ground that was mentioned in the beginning. Cheers to responsible content moderation!

Feel free to give your feedback on this article or suggestions about any other packages for Content Filtering in the comments. And don’t be awestruck if some of them mysteriously disappear. IYKYK.

About Author

Kaveri T S

And I was running far away Would I run off the world someday? Nobody knows I was dancing in the rain I felt alive, But now take me home..

Latest Posts