Client-side image moderation without the server round-trip
NSFWJS runs a TensorFlow.js classifier in the browser so images never need to reach a server for moderation.

What it does
NSFWJS is a browser-first (and Node-capable) library that classifies images into five categories—Drawing, Hentai, Neutral, Porn, and Sexy—using pre-trained TensorFlow.js models. It scores probabilities client-side, which means the pixels stay on the device instead of transiting to a remote API. The library wraps model loading, classification, and disposal into a small API that works with standard DOM elements like <img>, <video>, and <canvas>.
The interesting bit
The library ships with three built-in model architectures, but the real craft is in the bundling: it offers a nsfwjs/core entrypoint so you can tree-shake away the base64-encoded models you do not need, shrinking the payload. It also supports caching the loaded model in IndexedDB and swapping TensorFlow.js backends—WebGPU, WebGL, WASM, or CPU—depending on what the target device can handle.
Key highlights
- Client-side inference; images are not uploaded for classification.
- Claims ~90% accuracy with the small
MobileNetV2model and ~93% with the midsized variant. - Five output classes:
Drawing,Hentai,Neutral,Porn, andSexy. - Selective model bundling via
nsfwjs/coreto avoid pulling in unused model assets. - Supports multiple TensorFlow.js backends including WebGPU and WASM, plus Node.js execution.
Caveats
- The authors note the publicly hosted Cloudfront model has been moved due to hotlinking, so production deployments currently need to self-host the model files.
- The default bundled
MobileNetV2model adds roughly 3.5 MB to a bundle in base64 form; hosting the binary directly drops it to about 2.6 MB, which matters most if the model is loaded repeatedly without caching.
Verdict
Worth a look if you need client-side content filtering in a web app, React Native project, or Node service and would rather not ship user images to a third-party API. Skip it if you require guaranteed perfection or cannot afford the upfront model download.
Frequently asked
- What is infinitered/nsfwjs?
- NSFWJS runs a TensorFlow.js classifier in the browser so images never need to reach a server for moderation.
- Is nsfwjs open source?
- Yes — infinitered/nsfwjs is open source, released under the MIT license.
- What language is nsfwjs written in?
- infinitered/nsfwjs is primarily written in TypeScript.
- How popular is nsfwjs?
- infinitered/nsfwjs has 8.9k stars on GitHub.
- Where can I find nsfwjs?
- infinitered/nsfwjs is on GitHub at https://github.com/infinitered/nsfwjs.