Content moderator template

  • Node.js
  • Express

Mask profanity in comments, reviews and chat before they go live, and count what was caught.

A Node.js and Express app that cleans up user-generated text. Paste a comment, review or chat message and get it back with profanity masked, whether it was flagged, and how many words were caught. Use it by hand, or call its route when someone posts.

The content moderator app running

What it does

Masks, doesn’t delete
Replaces each offensive word with a mask character, so the rest of the comment still reads.
Counts what it caught
Returns how many words were masked, so you can hold heavy posts for review.
Your choice of mask
Use *, #, - or • for the masked letters.
Keeps your key private
The page calls your own server, which holds the key and limits each visitor to 10 checks a minute.

How it works

The route that masks a piece of text.

server.js
const MASKS = ['*', '#', '-', '•'];

// POST /api/moderate { text, mask }
app.post('/api/moderate', async (req, res) => {
  const text = str(req.body.text, 5000);
  const mask = MASKS.includes(req.body.mask) ? req.body.mask : '*';
  if (!text) return res.status(400).json({ error: 'Enter some text to check.' });

  try {
    const data = await callApi('profanityfilter', { body: { text, mask } });
    res.json({
      success: true,
      original: text,
      filtered: data.filteredText,
      isProfane: data.isProfane,
      profaneWords: data.profaneWords || 0,
      mask: data.mask
    });
  } catch (err) {
    res.status(err.status || 502).json({ error: err.message });
  }
});

See the whole file on GitHub

Deploy it

  1. Get a free API key

    The free plan includes 200 credits a month, no card needed. Create your key.

  2. Deploy it

    Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for APIVERVE_API_KEY: paste your key there.

  3. Open your app

    Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.

Try the Profanity Filter API — the call this template makes

Request
POSTapi.apiverve.com/v1/profanityfilter
Body
Verification
Format

No key required to try it. Get a key to use it in your app.

Example
{
  "status": "ok",
  "error": null,
  "data": {
    "isProfane": true,
    "filteredText": "Today is so **** hot! Why the **** would anyone go outside?",
    "mask": "*",
    "trimmed": false,
    "profaneWords": 2
  }
}

Build your own with Profanity Filter. Start with 200 free credits. One key unlocks all 300+ APIs.

Explore the catalog

300+ APIs on the same key and the same response shape.

Browse all APIs