explaingit

infinitered/nsfwjs

8,882TypeScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A TypeScript library that detects explicit or adult content in images entirely inside the browser using TensorFlow.js, no images are sent to a server, keeping user data private.

Mindmap

mindmap
  root((nsfwjs))
    What it does
      Classify images
      On-device AI
      No server upload
    Output Categories
      Neutral safe photo
      Drawing safe art
      Explicit content
    Available Models
      MobileNetV2 small
      MobileNetV2 mid
      InceptionV3 large
    Environments
      Browser
      Node.js
      React Native
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add automatic NSFW image filtering to a user-generated content platform without sending images to a server.

USE CASE 2

Screen profile photo uploads client-side in the browser before they reach your backend.

USE CASE 3

Run server-side NSFW image moderation in a Node.js pipeline to process images at upload time.

USE CASE 4

Build a browser extension that flags explicit images on web pages using on-device machine learning.

Tech stack

TypeScriptTensorFlow.jsNode.jsWebAssembly

Getting it running

Difficulty · easy Time to first run · 30min

Requires downloading a pre-trained model file of several MB on first use, caching in IndexedDB is recommended to avoid re-downloading on every page load.

In plain English

NSFWJS is a TypeScript library that checks whether an image contains adult or explicit content, and it does this work entirely inside the user's web browser using TensorFlow.js. No image is sent to a server. The library runs a machine-learning model locally, so user photos stay private and the detection happens as fast as the device can run it. The library sorts any image into one of five categories: Drawing (safe artwork, including anime), Hentai (explicit drawings), Neutral (ordinary safe-for-work photos), Porn (explicit photographic content), and Sexy (suggestive but not explicitly pornographic). It returns a confidence percentage for each category, so the calling application can decide how to act on the result. Accuracy is around 90 percent with the smaller model and around 93 percent with the mid-sized one. Three pre-trained models ship with the package: MobileNetV2 (the default, small and fast), MobileNetV2Mid (a graph-based mid-sized model), and InceptionV3 (a larger model expecting 299 by 299 pixel input). You load one with a single function call, classify an image element, and get back an array of predictions. The library can also run in Node.js for server-side processing, and it supports optional WebAssembly and WebGPU backends for faster inference on hardware that can take advantage of them. To avoid downloading the model on every page load, the library supports caching it in the browser's IndexedDB storage. Developers who want a smaller app bundle can host the model files themselves instead of relying on the bundled base64 copies, which reduces the download by roughly a third. For teams who need tree-shaking, a separate core entry point lets you import only the model definitions you actually use. The project is open source and maintained by Infinite Red. It works in standard browsers, in React Native via a community package, and in Node.js applications. The README includes working code examples for each environment.

Copy-paste prompts

Prompt 1
Using nsfwjs, show me how to load the MobileNetV2 model and classify a user-uploaded image in the browser, then block the upload if the Porn confidence score exceeds 0.5.
Prompt 2
Help me integrate nsfwjs into a React app so that profile photo uploads are checked client-side before being sent to the server, with a user-friendly error message on rejection.
Prompt 3
Show me how to run nsfwjs in Node.js to batch-process a folder of images and output a CSV listing each file and its highest-scoring content category.
Prompt 4
How do I cache the nsfwjs model in IndexedDB so users only download it once per browser, and how do I verify the cached version is still valid?
Open on GitHub → Explain another repo

← infinitered on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.