npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ncbijs/pubmed

v0.1.1

Published

High-level PubMed article search and retrieval client

Readme

Runtime: Browser + Node.js


Why

The raw PubMed API (E-utilities) requires managing History Server WebEnv tokens, manual pagination, XML parsing, and date segmentation for large result sets. That's a lot of boilerplate between you and the articles you need.

@ncbijs/pubmed wraps all of that into a fluent interface: search("CRISPR").author("Doudna").fetchAll().

  • Fluent query builder with filters for author, journal, MeSH, date range, publication type, and proximity search
  • Automatic date segmentation for queries exceeding the 10,000-result API limit
  • Streaming batches via AsyncIterableIterator for memory-efficient processing
  • Citation graph traversal — find related articles, citing articles, and references
  • Parsed article objects with structured abstracts, MeSH headings, grants, and all identifiers

Install

npm install @ncbijs/pubmed

Quick start

import { PubMed } from '@ncbijs/pubmed';

const pubmed = new PubMed({
  tool: 'my-app',
  email: '[email protected]',
  apiKey: 'your-ncbi-api-key',
});

const articles = await pubmed
  .search('CRISPR')
  .author('Doudna')
  .dateRange('2020/01/01', '2024/12/31')
  .freeFullText()
  .fetchAll();

for (const article of articles) {
  console.log(`${article.pmid}: ${article.title}`);
}

API

new PubMed(config)

const pubmed = new PubMed({
  tool: 'my-app',
  email: '[email protected]',
  apiKey: 'your-ncbi-api-key',
  maxRetries: 3,
});

| Parameter | Type | Required | Description | | ------------ | -------- | -------- | ----------------------------------------------------------- | | tool | string | Yes | Your application name (NCBI requires this). | | email | string | Yes | Contact email (NCBI requires this). | | apiKey | string | No | NCBI API key. Increases rate limit from 3 to 10 req/second. | | maxRetries | number | No | Maximum retry attempts on transient failures. |

search(term)

Start building a PubMed query. Returns a PubMedQueryBuilder.

const query = pubmed.search('cancer immunotherapy');

PubMedQueryBuilder

Chain filters to narrow your search, then execute with fetchAll() or batches().

.author(name)

Filter by author name.

pubmed.search('CRISPR').author('Doudna JA');

.journal(isoAbbrev)

Filter by journal ISO abbreviation.

pubmed.search('machine learning').journal('Nature');

.meshTerm(descriptor)

Filter by MeSH descriptor.

pubmed.search('diabetes').meshTerm('Insulin Resistance');

.dateRange(from, to)

Filter by publication date. Format: "YYYY/MM/DD".

pubmed.search('COVID-19').dateRange('2020/01/01', '2023/12/31');

.publicationType(type)

Filter by publication type.

pubmed.search('statins').publicationType('Meta-Analysis');

Available types: 'Review', 'Clinical Trial', 'Meta-Analysis', 'Randomized Controlled Trial', 'Systematic Review', 'Case Reports', 'Letter', 'Editorial', 'Comment', 'Practice Guideline'.

.freeFullText()

Only include articles with free full text available.

pubmed.search('Alzheimer').freeFullText();

.sort(field)

Set the sort order.

pubmed.search('oncology').sort('pub_date');

| Value | Description | | --------------- | ------------------------ | | 'relevance' | Best match (default). | | 'pub_date' | Most recent first. | | 'Author' | Alphabetical by author. | | 'JournalName' | Alphabetical by journal. |

.proximity(terms, field, distance)

Proximity search — find terms within a given word distance in a field.

pubmed.search('cancer').proximity('tumor suppressor', 'tiab', 3);

.limit(n)

Cap the maximum number of results returned.

pubmed.search('RNA').limit(100);

.buildQuery()

Return the constructed PubMed query string without executing it.

const query = pubmed.search('CRISPR').author('Doudna').buildQuery();
// "CRISPR AND Doudna[au]"

Returns string.

.fetchAll()

Execute the query and return all matching articles. Automatically handles date segmentation when results exceed the 10,000-result API limit.

const articles = await pubmed.search('CRISPR').fetchAll();

Returns Promise<ReadonlyArray<Article>>.

.batches(size?)

Stream results in batches for memory-efficient processing. Default batch size is 500.

for await (const batch of pubmed.search('oncology').batches(200)) {
  console.log(`Processing ${batch.length} articles`);
}

Returns AsyncIterableIterator<ReadonlyArray<Article>>.

Note: batches() does not support date segmentation. For queries exceeding 10,000 results, use fetchAll() or add filters to narrow results.

related(pmid)

Find articles related to a given PMID, sorted by relevancy score.

const related = await pubmed.related('35266103');

for (const article of related) {
  console.log(`${article.pmid} (score: ${article.relevancyScore})`);
}

Returns Promise<ReadonlyArray<RelatedArticle>>.

citedBy(pmid)

Get articles that cite the given PMID.

const citations = await pubmed.citedBy('35266103');

Returns Promise<ReadonlyArray<Article>>.

references(pmid)

Get articles referenced by the given PMID.

const refs = await pubmed.references('35266103');

Returns Promise<ReadonlyArray<Article>>.

Types

All types are exported for use in your own interfaces:

import type { Article, RelatedArticle, PublicationType, PubMedSort } from '@ncbijs/pubmed';

Article

interface Article {
  readonly pmid: string;
  readonly title: string;
  readonly abstract: {
    structured: boolean;
    text: string;
    sections?: ReadonlyArray<{ label: string; text: string }>;
  };
  readonly authors: ReadonlyArray<{
    lastName?: string;
    foreName?: string;
    collectiveName?: string;
    affiliations: ReadonlyArray<string>;
  }>;
  readonly journal: {
    title: string;
    isoAbbrev: string;
    issn?: string;
    volume?: string;
    issue?: string;
  };
  readonly publicationDate: { year: number; month?: number; day?: number };
  readonly mesh: ReadonlyArray<{
    descriptor: string;
    qualifiers: ReadonlyArray<string>;
    majorTopic: boolean;
  }>;
  readonly articleIds: { pmid: string; doi?: string; pmc?: string; pii?: string };
  readonly publicationTypes: ReadonlyArray<string>;
  readonly grants: ReadonlyArray<{ grantId: string; agency: string; country: string }>;
  readonly keywords: ReadonlyArray<string>;
}

RelatedArticle

Extends Article with a relevancyScore: number field.

PublicationType

Union of standard PubMed publication types: 'Review' | 'Clinical Trial' | 'Meta-Analysis' | ....

PubMedSort

'relevance' | 'pub_date' | 'Author' | 'JournalName'