Skip to content

Getting version number of package

This tutorial is part of package functions documentation in Iconify Tools.

Function getPackageVersion() is a simple function that retrieves version number from package.json in target directory.

It is used by downloadNPMPackage() to retrieve version number of package that has already been downloaded and extracted. It can also be used to get version number of package downloaded from Git repository (as shown in example below).


Function has the following parameter:

  • target, string. Target directory, without "/package.json".

Function returns version number as string.

Also see getNPMVersion().

Function is asynchronous.


tsimport { downloadGitHubRepo, getPackageVersion } from '@iconify/tools';

// GITHUB_TOKEN=ghp_12345 node example.js
const token = process.env.GITHUB_TOKEN || '';

(async () => {
   // Download GitHub repository
   const result = await downloadGitHubRepo({
       target: 'downloads/bi',
       user: 'twbs',
       repo: 'icons',
       branch: 'main',

   // Get version from downloaded package
   const version = await getPackageVersion(result.contentsDir);

   // '1.7.0'
   console.log('Version:', version);

Released under the Apache 2.0 License.