3.3.3 • Public • Published

Research Object Crate (RO-Crate) JavaScript Library

This is a JavaScript library to create and manipulate Research Object Crate.


Install the library:

npm install ro-crate

Note: The minimum Node.js version is 16.11.0.

Docs & Other Resources


Import the ROCrate class and create a new empty crate with default configurations:

const {ROCrate} = require('ro-crate');
const crate = new ROCrate();

The ROCrate constructor accepts two optional arguments:

const fs = require('fs');

// load existing metadata
const data = JSON.parse(fs.readFileSync('ro-crate-metadata.json', 'utf8'));

// create a crate using the existing data and
// configure the crate to return a property of an Entity as an array and resolve linked entity as nested object
const crate = new ROCrate(data, { array: true, link: true });

To add an Entity to the crate:

// A license
const license = {
    '@id': '',
    '@type': 'CreativeWork',
    'description': 'Attribution 4.0 International (CC BY 4.0) ...',
    'name': 'CC BY 4.0'
// add the license as an unconnected Entity

// add the license to the root dataset
crate.rootDataset.license = {'@id': license['@id']};
// or alternatively, add a new entity directly into a property of other entity :
crate.rootDataset.license = license;

Use an entity just like a normal object:

let lic = create.getEntity(license['@id']);
console.log(; // prints 'CC BY 4.0';
// set a property directly = 'CC BY 4.0 dummy';
// or with the setProperty method
crate.setProperty(license['@id'], 'name', 'CC BY 4.0 dummy');

console.log(; // prints 'CC BY 4.0 dummy';

Modifying an array of values in the property is not supported yet:

lic.test = [1,2,3];
lic.test.push(4); // this does not work
console.log(lic.test); // prints '[1,2,3]';
// use this instead
lic.test = lic.test.concat(4);
// or this
crate.addValues(license['@id'], 'test', 4);

Root Dataset is a special entity that is mandated by the standard:

const rootDataset = crate.rootDataset; = 'Tutorial Crate';
rootDataset.description = 'This is an example crate for educational purposes.'
const today = new Date().toISOString().split('T')[0]
rootDataset.datePublished = today;

The value of the returned property can be set to be always as an array:

const crate1 = new ROCrate();
const crate2 = new ROCrate({array: true}); = 'Tutorial Crate';
crate1.rootDataset.test = ['test1', 'test2']; = 'Tutorial Crate';
crate2.rootDataset.test = ['test1', 'test2'];
console.log(; // return 'Tutorial Crate'
console.log(; // return ['test1', 'test2']
console.log(; // return ['Tutorial Crate']
console.log(; // return ['test1', 'test2']

Linked entities can be automatically resolved as nested objects:

const crate1 = new ROCrate();
const crate2 = new ROCrate({link: true});
const crate3 = new ROCrate({link: true, array: true});
crate1.rootDataset.license = license;
crate2.rootDataset.license = license;
crate3.rootDataset.license = license;
console.log(; // return undefined
console.log(crate1.rootDataset.license); // return {'@id': ''}
console.log(; // return 'CC BY 4.0'
console.log(; // return undefined, property license is a array
console.log(crate3.rootDataset.license[0].name); // return 'CC BY 4.0'

To save the rocrate data to a file, use JSON.stringify:

// Write pretty-printed JSONLD into the directory
fs.writeFileSync('ro-crate-metadata.json', JSON.stringify(crate, null, 2));

For more usage examples, see the test files under the test directory.

For more details, refer to the full API documentation.

HTML Rendering

Use the RO-Crate-HTML to generate a HTML preview from the RO-Crate Metadata File ro-crate-metadata.json.

Simple crate checker

There is a script included with this library that can check crates.

Check a crate:

roccheck /path/to/crate/directory

This is produce a simple report.

Package Sidebar


DownloadsWeekly Downloads






Unpacked Size

257 kB

Total Files


Last publish


  • moisbo
  • mikelynch
  • ptsefton
  • alvinsw