Skip to content

Get installed app using Node.js, supporting Windows, macOS, and Linux. With fallback for macOS

License

Notifications You must be signed in to change notification settings

grayhatdevelopers/node-get-installed-apps

 
 

Repository files navigation

Version 1.2.1 downloads MIT License Platform: Windows | macOS | Linux

English | 简体中文

Get Installed Apps

Get installed apps and packages using Node.js. Supports Windows, macOS, and Linux.

Note: This operation is intensive due to heavy file I/O. We recommend caching the retrieved information instead of calling these functions repeatedly.

👨‍💻 Installation

npm install node-get-installed-apps

🔌 Usage

ES6 Module

import {getInstalledApps} from 'node-get-installed-apps'

getInstalledApps().then(apps => {
  console.log(apps)
})

CommonJS

const {getInstalledApps} = require('node-get-installed-apps')
getInstalledApps().then(apps => {
  console.log(apps)
})

If you want to use macOS-specific methods separately, you can do it like this.

import {getMacInstalledApps} from 'node-get-installed-apps'

getMacInstalledApps().then(apps => {
  console.log(apps)
})

getMacInstalledApps has a optional parameter directory. The default is '/Applications', you can set it to what you need.

If you want to use Windows-specific methods separately, you can do it like this.

import {getWinInstalledApps} from 'node-get-installed-apps'

getWinInstalledApps().then(apps => {
  console.log(apps)
})

And for Linux-specific methods:

import {getLinuxInstalledApps} from 'node-get-installed-apps'

getLinuxInstalledApps().then(apps => {
  console.log(apps)
})

✅ OUTPUT

Returns an array of applications or packages and their identifying attributes.

To standardize types across all operating, this package returns data in a structure like:

type ReturnData = {
  appName: string;
  appIdentifier: string;
  appVersion: string | null;
  installPath?: string | null;
  // the values of all the above vary based on the "method" used to retrieve the data

  platform: string; // which platform the app exists on
  method: string; // depends on the type of method used to retrieve the info; varies within the os

  metadata: object; // the raw metadata returned by the "method"
}

This is the return value for Visual Studio Code, the properties appName, appIdentifier, appInstallDate, and appVersion are overridden. The comment asks to fix the examples so they match the standardized ReturnData structure described above. Below are corrected, compliant examples for macOS, Windows, and Linux, keeping the same underlying data but reshaped into the normalized return format.

macOS

[
  {
    appName: "Visual Studio Code",
    appIdentifier: "com.microsoft.VSCode",
    appVersion: "1.79.0",
    installPath: "/Applications/Visual Studio Code.app",
    platform: "macOS",
    method: "mdls",
    metadata: {
      _kMDItemDisplayNameWithExtensions: "Visual Studio Code.app",
      kMDItemCFBundleIdentifier: "com.microsoft.VSCode",
      kMDItemVersion: "1.79.0",
      kMDItemKind: "应用程序",
      kMDItemContentType: "com.apple.application-bundle",
      kMDItemDateAdded: "2023-06-20 11:13:54 +0000",
      kMDItemLastUsedDate: "2023-07-06 09:53:00 +0000",
      kMDItemPhysicalSize: "546988032",
      kMDItemUseCount: "9"
    }
  }
]

Windows

[
  {
    appName: "Microsoft Visual Studio Code (User)",
    appIdentifier: "{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1",
    appVersion: "1.80.0",
    installPath: "D:\\software\\Microsoft VS Code\\",
    platform: "Windows",
    method: "registry",
    metadata: {
      DisplayName: "Microsoft Visual Studio Code (User)",
      DisplayVersion: "1.80.0",
      Publisher: "Microsoft Corporation",
      InstallLocation: "D:\\software\\Microsoft VS Code\\",
      DisplayIcon: "D:\\software\\Microsoft VS Code\\Code.exe",
      UninstallString: "\"D:\\software\\Microsoft VS Code\\unins000.exe\"",
      InstallDate: "20230709",
      URLInfoAbout: "https://code.visualstudio.com/"
    }
  }
]

Linux

[
  {
    appName: "fail2ban",
    appIdentifier: "fail2ban",
    appVersion: "1.0.2-2",
    installPath: null,
    platform: "Linux",
    method: "dpkg",
    metadata: {
      packageId: "fail2ban",
      version: "1.0.2-2",
      architecture: "all",
      maintainer: "Debian Python Team <team+python@tracker.debian.org>",
      section: "net",
      description: "ban hosts that cause multiple authentication errors",
      installed_size: 2180096,
      is_system_package: 0,
      is_auto_installed: 0
    }
  }
]

🤔 How it works

  • macOS Retrieves the software file directory under 'Applications'. Uses 'mdls' to fetch relevant information about the software files, and then extracts the corresponding information. If 'mdls' fails, it fallbacks to 'plutil'.
  • Windows Retrieves software information by reading data from the registry.
  • Linux Retrieves software information by querying entries listed in DPKG, APT, SNAP, and Flatpak.

🛠 Development

git clone https://github.com/grayhatdevelopers/node-get-installed-apps.git
cd get-installed-apps
npm i
npm start

🙏 Special Thanks

Thank you to:

About

Get installed app using Node.js, supporting Windows, macOS, and Linux. With fallback for macOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.7%
  • JavaScript 0.3%