Adult content moderation using NodeJs

A few months ago my friend Bill was creating an application in  Nodejs and he ran into a situation where He wanted to block the upload of nude/adult images. An adult content moderation using NodeJs sounds interesting. Well, just another day I was withstanding the same situation, I was thinking should I calculate skin pixel score or I should manually moderate each Image. Then I asked Bill and he suggested me to use Cloudinary.

So I gave look to the Cloudinary and their services are really great. I used Cloudinary’s content moderation service, so here I would like to share a piece of code. In this article, we will write down a script which will block the upload of the Nude image in Nodejs. We will go step by step from creating a Cloudinary account to running the Nodejs server.

1. Creating Cloudinary Account

Go to the Cloudinary website signup and create an account, where you will get the Cloud NameAPI Key and API Secret as shown in below Image. Adult content moderation using NodeJs Account key

2. Activating Cloudinary Add-on

To recognize and block the adult content, you have to activate Rekognition AI Moderation add on. So first Go to add-ons page and then you will see the first add on named as  Rekognition AI Moderation. Now click on Rekognition AI Moderation add on and select whatever plan suits you.

3. Building Nodejs server

Let’s create a package.json file by using npm init command, and below is my package.json file.


4. Script for Adult content moderation using NodeJs

You can use the npm install command to install all the dependencies or you can do the hard work. Create a server.js file in your root directory. Now copy the below code into the server.js and you are good to go.


Explanation: In the above Server class, there are two methods that are important.

First method is appConfig() and second method is includeRoutes(), let talk about both of them.

1. appConfig(): In this method, I have setup the Cloudinary configuration.

2. includeRoutes(): In this method, I have we have /upload post URL to handle the upload request. Inside that, we will upload the image on the Cloudinary.

5. conclusion

That was really quick, isn’t it?  So this is how I automated the image moderation for my application saving tons of hard work.please let me know your thoughts on this topic in below comment box.