Narou API Wrapper
Narou is a TypeScript library that provides a fluent interface wrapper for the Narou Developer APIs (dev.syosetu.com), which allow programmatic access to data from the Japanese web novel publishing site Shousetsuka ni Narou. It supports various APIs including novel search, ranking retrieval, ranking history, and R18 novel search. The library currently stands at version 2.0.1, with recent releases showing active maintenance and minor bug fixes. It differentiates itself by offering a method-chaining syntax, full TypeScript type safety, and multi-environment compatibility, automatically selecting between native `fetch` for Node.js and JSONP for browser environments. It also boasts comprehensive coverage of all Narou Developer APIs, ensuring access to the full range of data provided by the Narou Developer Portal.
Common errors
-
ReferenceError: require is not defined
cause Attempting to use CommonJS `require()` syntax with this ESM-first library in a module context or a Node.js version configured for ESM.fixUse ES module import syntax: `import { search } from 'narou';` instead of `const { search } = require('narou');`. -
TypeError: (0, _narou_browser__WEBPACK_IMPORTED_MODULE_0__.search) is not a function
cause Attempting to use the `narou/browser` specific import in a Node.js environment, or vice-versa, or an incorrect bundling setup.fixEnsure you are using `import { search } from 'narou'` for Node.js and `import { search } from 'narou/browser'` for browser environments. Check your bundler configuration to ensure correct module resolution. -
UnhandledPromiseRejectionWarning: TypeError: fetch is not a function
cause Running the Node.js version of the library in a Node.js environment older than v18, which does not have `fetch` globally available, after `node-fetch` was removed in v1.0.0.fixUpgrade your Node.js environment to v18 or newer, or install a `fetch` polyfill (e.g., `node-fetch`) and ensure it's globally available before importing `narou`.
Warnings
- breaking Version 1.0.0 removed the internal `node-fetch` dependency. This might affect applications relying on specific `node-fetch` behavior or polyfills, as the library now uses native `fetch` in Node.js environments (which requires Node.js 18+ or a global polyfill for earlier Node.js 16+ versions).
- breaking The package now requires Node.js version 16.0.0 or higher. Older Node.js versions are not supported and will lead to runtime errors or installation failures.
- gotcha When targeting browser environments, a specific import path (`narou/browser`) is required. Importing from the main 'narou' package directly in a browser environment will result in module resolution errors or incorrect functionality as it's optimized for Node.js.
- gotcha While the library supports both Node.js and browser environments, the `rankingHistory` function in the browser version did not correctly respect `fetchOptions` prior to v2.0.1.
Install
-
npm install narou -
yarn add narou -
pnpm add narou
Imports
- search
const { search } = require('narou')import { search } from 'narou' - ranking
import ranking from 'narou'
import { ranking } from 'narou' - search
import { search } from 'narou'import { search } from 'narou/browser' - Genre
import { Genre } from 'narou'
Quickstart
import { search, ranking } from 'narou';
import { Genre, Order, RankingType } from 'narou';
async function getNovels() {
// Search for 'isekai' romance novels, ordered by favorite count
const searchResult = await search('異世界')
.genre(Genre.RenaiIsekai)
.order(Order.FavoriteNovelCount)
.limit(10)
.execute();
console.log(`Found ${searchResult.allcount} novels matching the criteria.`);
for (const novel of searchResult.values) {
console.log(`- ${novel.title} (NCODE: ${novel.ncode})`);
}
// Get daily ranking for a specific date
const rankingResult = await ranking()
.date(new Date('2023-04-01'))
.type(RankingType.Daily)
.execute();
console.log('\nDaily Ranking (2023-04-01):');
for (const novel of rankingResult) {
console.log(`- Rank ${novel.rank}: NCODE ${novel.ncode} (Points: ${novel.pt})`);
}
}
getNovels().catch(console.error);