Managing DOIs with Node.js: creation and metadata updates

The DOI (Digital Object Identifier) is a unique and permanent identifier used to reference digital resources such as scientific articles, datasets, and publications. With Node.js, it is possible to interface with DOI registration APIs (such as Crossref or DataCite) to create, update, and manage these identifiers. In this article, we will see how to generate and manage a DOI using Node.js.

Prerequisites

  • An account with a DOI provider (e.g., DataCite).
  • An API key or credentials to authenticate with the DOI service.

Installing Dependencies

We start by creating a new Node.js project and installing the libraries required to make HTTP requests, such as axios:

mkdir doi-manager
cd doi-manager
npm init -y
npm install axios

Creating a DOI

The process of creating a DOI involves sending an HTTP request to the provider’s API. In the following example, we will use DataCite. The request includes metadata in JSON format and the desired DOI (or left empty if you want it to be generated automatically).

const axios = require('axios');

const DATACITE_API = 'https://api.test.datacite.org/dois';
const API_USERNAME = 'USERNAME';
const API_PASSWORD = 'PASSWORD';

async function createDOI() {
  const metadata = {
    data: {
      type: 'dois',
      attributes: {
        prefix: '10.1234',
        event: 'publish',
        url: 'https://example.org/resource',
        titles: [{ title: 'Resource Title' }],
        creators: [{ name: 'John Doe' }],
        publisher: 'Test Publisher',
        publicationYear: 2025
      }
    }
  };

  try {
    const response = await axios.post(DATACITE_API, metadata, {
      auth: { username: API_USERNAME, password: API_PASSWORD },
      headers: { 'Content-Type': 'application/vnd.api+json' }
    });
    console.log('DOI created:', response.data.data.id);
  } catch (error) {
    console.error('Error while creating DOI:', error.response?.data || error.message);
  }
}

createDOI();

Updating DOI Metadata

If the DOI has already been registered, it is possible to update its metadata by making a PUT request to the corresponding endpoint:

async function updateDOI(doi) {
  const updatedMetadata = {
    data: {
      id: doi,
      type: 'dois',
      attributes: {
        titles: [{ title: 'Updated Resource Title' }]
      }
    }
  };

  try {
    const response = await axios.put(`${DATACITE_API}/${doi}`, updatedMetadata, {
      auth: { username: API_USERNAME, password: API_PASSWORD },
      headers: { 'Content-Type': 'application/vnd.api+json' }
    });
    console.log('DOI updated:', response.data.data.id);
  } catch (error) {
    console.error('Error while updating DOI:', error.response?.data || error.message);
  }
}

updateDOI('10.1234/abcd1234');

Conclusions

With Node.js and libraries like axios, it is relatively simple to interact with DOI registration APIs. It is essential to ensure the use of test environments (such as api.test.datacite.org) before registering real DOIs, and to comply with the metadata requirements imposed by the chosen provider.

Back to top