Image moderation is a challenge for any website or application that accepts user-uploaded content. Between paid services that transmit your files to remote servers and expensive in-house solutions to develop, there is a middle ground: NSFWJS. This open-source JavaScript library, maintained by the Infinite Red studio, allows you to classify potentially explicit images directly in the browser or in Node.js, without ever sending the files to an external service. In practice, it relies on TensorFlow.js to run a computer vision model client-side and assign each image a score across five categories. For a web developer, this means a quick first filter to set up, free and privacy-friendly, ideal for identifying risky content before it appears on a platform. In the following sections, we detail exactly what NSFWJS is, how it works, its concrete use cases, its advantages, its business model, and what you need to take away from it.
What is NSFWJS?
NSFWJS is a JavaScript library designed to quickly identify potentially inappropriate images, as its own description states: helping to spot these images entirely in the client’s browser. The project is backed by Infinite Red and distributed under the MIT license, making it free, open, and modifiable. Technically, it relies on TensorFlow.js and offers several pre-trained models, notably MobileNetV2 and InceptionV3. From a provided image, the model calculates a probability for five distinct classes: Drawing (safe drawings, including animation), Hentai, Neutral (neutral content), Porn, and Sexy. The library works just as well in the browser as it does server-side with Node.js, and a companion package exists for React Native applications.
Key Features
The core of NSFWJS lies in a simple API. After loading the model with the load method, you call classify, passing it an image source: HTML image tag, canvas element, video, raw image data, or a TensorFlow.js tensor. The function returns the list of the five classes along with their probability, leaving the developer to choose the blocking threshold. Three models are offered depending on the trade-off sought between size and accuracy: a small MobileNetV2 model in 224×224, an intermediate variant, and a heavier InceptionV3 model in 299×299. The announced accuracy is around 90% for the small model and 93% for the intermediate model. The library supports several compute backends (WebGL, WebGPU, WASM, CPU) and can cache models in the browser via IndexedDB to speed up subsequent loads. An open-source Chrome extension project, NSFW Filter, actually relies on NSFWJS to hide sensitive images during browsing, illustrating the library’s flexibility.
Use Cases
NSFWJS naturally finds its place in content moderation on platforms that accept image uploads: forums, social networks, marketplaces, or comment sections. Since the analysis takes place client-side, you can block or blur a suspicious image even before it is sent to the server, which reduces bandwidth and protects user privacy. Browser extension developers use it to automatically filter displayed images, much like the NSFW Filter extension. The nsfwjs-mobile package paves the way for React Native applications that want to integrate content control on mobile. Finally, in a Node.js environment, NSFWJS can serve as a first sorting layer in an image processing pipeline, for example to flag content for manual review.
Advantages
The main advantage of NSFWJS is its entirely client-side operation: no images are transmitted to a third-party service, a strong argument for privacy and compliance. Next comes the total free-of-charge nature under the MIT license, which allows commercial use without fees or quotas. The library is lightweight to integrate, relies on the already well-documented TensorFlow.js ecosystem, and leaves the developer free to choose their model and thresholds. Its multi-environment compatibility (browser, Node.js, React Native) and its active open-source community make it a reusable building block in various contexts, from prototype to production product.
Pricing
NSFWJS is an open-source project published under the MIT license: it is free and has no paid tiers, subscriptions, or API keys to purchase. There is no official commercial hosted API or managed service: you install the library via npm or yarn and host the models yourself if you wish. The only potential costs are indirect, related to your own infrastructure if you run it in Node.js at scale. This lack of fees makes it a particularly attractive solution for budget-limited projects or experiments.
Conclusion
NSFWJS is a pragmatic response to the need for filtering sensitive images without relying on an external service. Free, open-source, and executed client-side, it offers developers a quick-to-deploy first safeguard that respects privacy. However, its 90% to 93% accuracy and the absence of a no-code interface destine it for technical teams, and it benefits from being supplemented by human review for high-stakes use cases. For a web or mobile developer looking for a free and reliable image moderation solution, it is an option worth knowing.