How to Install Howler.js Using npm

This article provides a quick, step-by-step guide on how to install the Howler.js audio library using Node Package Manager (npm). You will learn the exact terminal commands needed to add Howler.js to your JavaScript project, how to verify the installation, and how to import it into your codebase to begin playing audio.

Prerequisites

Before installing Howler.js, ensure that you have Node.js and npm installed on your computer. You also need an active project directory containing a package.json file. If you do not have one, you can initialize a project by running npm init -y in your terminal.

Step 1: Install Howler.js

To install the latest stable version of Howler.js, open your terminal, navigate to your project’s root directory, and run the following command:

npm install howler

This command downloads the Howler.js package from the npm registry and saves it inside your node_modules folder.

Step 2: Verify the Installation

To confirm that Howler.js was successfully installed, open your project’s package.json file. You should see howler listed under the dependencies object:

"dependencies": {
  "howler": "^2.2.4"
}

(Note: The version number may be different depending on the latest release).

Step 3: Import and Use Howler.js in Your Code

Once installed, you can integrate Howler.js into your JavaScript files. Depending on your project setup, use one of the following methods to import it:

Using ES Modules (Modern JavaScript/Bundlers like Webpack, Vite, or Rollup):

import { Howl, Howler } from 'howler';

const sound = new Howl({
  src: ['audio.mp3']
});

sound.play();

Using CommonJS (Node.js environments or Browserify):

const { Howl, Howler } = require('howler');

const sound = new Howl({
  src: ['audio.mp3']
});

sound.play();