Skip to content

How create a spam filter in express.js or how to filter objects based on the word in the key values?

I want create simple spam filter. I dont have an inbox yet but I was thinking when the emails are recived I could make a GET request and filter the object based on the words mentioned in the message. If the posted object is

[{“id”:”1″ “email”:””, “cc”: “”,
“message”: “You have a chance to win a lottery and be a millionaire” },

{“id”:”1″ “email”:””, “cc”: “”,
“message”: “hello how are you doing” } ]

I want to filter the object with id===1 that contains a combination of words “lottery”,”win”,”millionaire” in the message

I have come across Naive Bayes spam filtering algorithm but I don’t know how to integrate it with Express.

Any help is appreciated.


you can do this way by using filter()

  (item) => != 1 || !item.message.includes("lottery") || !item.message.includes("win") || !item.message.includes("millionaire")