Registry / http-networking / nhentai-api

nhentai-api

JSON →
library9.9.9jsnpmunverified

nhentai-api is a Node.JS client library designed for interacting with the undocumented APIs of nhentai.net. Currently at version 3.4.3, the library exhibits an active release cadence, with recent minor updates addressing type fixes and introducing new features such as `getRandomBook`. It provides an objective-oriented API abstraction, facilitating tasks like bidirectional inspection (e.g., retrieving an image from a book or a book from an image). A key differentiating feature is its built-in support for proxies, allowing users to configure custom agents for requests, enhancing flexibility and privacy. The library focuses on returning structured data from the nhentai.net API and provides direct URLs for binary content like images. It also offers advanced search functionalities and helper methods for filtering and managing various tag types. The package ships with comprehensive TypeScript types, significantly improving developer experience and type safety.

npm install nhentai-api
INSTALL
IMPORT
SIG · NHENTAI-API
N
nhentai-api
http-networkingjavascriptv9.9.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

API
import { API } from 'nhentai-api';
const API = require('nhentai-api');
CommonJS users should destructure the `API` class from the `require` call, e.g., `const { API } = require('nhentai-api');`
TagTypes
import { TagTypes } from 'nhentai-api';
const TagTypes = require('nhentai-api').TagTypes;
Used for filtering tags by type. CommonJS users should also destructure `TagTypes` from the `require` call. It represents an object with tag type constants.
API as NhentaiAPI
import { API as NhentaiAPI } from 'nhentai-api';
import NhentaiAPI from 'nhentai-api';
The `API` class is a named export; there is no default export. Renaming on import is done via `as` keyword for clarity or to avoid naming conflicts.

This quickstart initializes the nhentai API client, fetches a specific book by ID, retrieves a random book, performs a search query, and demonstrates iterating through search results using an async generator. It logs key information like book titles, image URLs, and tag details.

import { API, TagTypes } from 'nhentai-api'; async function main() { const api = new API(); console.log('Fetching a specific book (ID: 177013)...'); try { const book = await api.getBook(177013); console.log(`Book Title: ${book.title.pretty}`); console.log(`Cover URL: ${api.getImageURL(book.cover)}`); if (book.pages.length > 0) { console.log(`First page URL: ${api.getImageURL(book.pages[0])}`); } console.log(`Tags: ${book.tags.map(t => t.name).join(', ')}`); console.log(`Artists: ${book.artists.map(a => a.name).join(', ')}`); console.log('\nFetching a random book...'); const randomBook = await api.getRandomBook(); console.log(`Random Book ID: ${randomBook.id}`); console.log(`Random Book Title: ${randomBook.title.pretty}`); console.log('\nSearching for books with query "test" (first page)...'); const searchResult = await api.search('test'); console.log(`Search query: "${searchResult.query}"`); console.log(`Total search pages: ${searchResult.pages}`); if (searchResult.books.length > 0) { console.log(`First book from search: ${searchResult.books[0].title.pretty}`); } // Example of using search generator console.log('\nUsing search generator for the first 2 pages of "hentai"...'); let pageCount = 0; for await (const search of api.searchGenerator('hentai')) { console.log(` Page ${search.page}: Found ${search.books.length} books.`); if (search.page >= 2) break; } } catch (error: any) { console.error('An error occurred during API interaction:', error.message); } } main();
Debug
Known issues
breakingMajor version updates to `3.x` may introduce breaking changes compared to previous major versions. While specific changes are not detailed in the provided release notes, it is recommended to review the full changelog on GitHub when upgrading from `2.x` or earlier.
fix
Consult the official GitHub repository for a complete list of breaking changes and migration guides when upgrading across major versions.
affects: >=3.0.0
gotchaThe `API#getRandomBook` method was added in version `3.4.1`. Attempting to call this method on earlier versions will result in an error or undefined behavior.
fix
Ensure your `nhentai-api` package is updated to version `3.4.1` or higher to utilize the `getRandomBook` functionality.
affects: <3.4.1
gotchaInitial `3.0.2` release notes explicitly state 'Has no tests yet'. This could imply a higher risk of unexpected behavior or bugs in early `3.x` versions compared to later, more stable releases.
fix
For production applications, consider using more recent patch versions of the `3.x` series (e.g., `3.4.x`) that have likely incorporated bug fixes and improved stability.
affects: 3.0.2
Errors
Common errors & fixes
ReferenceError: API is not defined
Attempting to use `API` class without proper CommonJS destructuring or incorrect ESM import.
fix
For CommonJS, use `const { API } = require('nhentai-api');`. For ES Modules, use `import { API } from 'nhentai-api';`.
TypeError: api.getRandomBook is not a function
Attempting to call `getRandomBook` on an `API` instance from a version older than `3.4.1`.
fix
Update your `nhentai-api` package to version `3.4.1` or newer using `npm update nhentai-api` or `yarn upgrade nhentai-api`.
UnhandledPromiseRejectionWarning: Error: Request failed with status code 404 (or 429, 500)
The requested book ID does not exist (404), too many requests were made (429), or there's a server-side issue (5xx).
fix
Validate the book ID, implement exponential backoff for rate limiting (429), or wrap API calls in `try/catch` blocks to handle network/API errors gracefully.
Upgrade
Version history
9.9.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
nhentai-api — npm install nhentai-api · libregistry