Using npm in browser?

Hello everyone! I am making a radio and I wanted to know how I can make it show the name of the music with its duration when the music is heard. I’m trying to use npm to do that but the browser doesn’t allow npm.

The duration and currentTime are easy enough. But the title of the song is not. That is external, or file metadata. You might be able to use an audio track or label to read from but you would still need to add the title yourself. I guess if you named the files after the song title you might also be able to construct a proper title from that file name and display it.


Use a bundler with a package

I tried with this code using my web page, but it tells me the following “Uncaught ReferenceError: require is not defined at” and from what I was looking for you could use browserify but it still doesn’t work

<h1>Song names</h1>
<script>
const icy = require('icy');

const url = 'http://strm112.1.fm/dubstep_mobile_mp3';

icy.get(url, function(res) {
    res.on('metadata', function(data) {
        const parsed = icy.parse(data);
        console.log(parsed)
    })
});
</script>

You need to wait for the image to finish uploading before posting. You can edit the post.

We would prefer to see the actual code.

Use the “preformatted text” tool in the editor (</>) to add backticks around the code.

there I have edited it with the code that I try to use in the browser

Are you actually linking to the browserify bundle?

I get CORS blocked when I try your code, but the bundle does work (no require errors). I tried with a different radio station that had https but it too got blocked. I can’t find something to test it with that actually works.


This one works in the browser without browserify

But again, only the link they give in the docs actually worked for me. Everything else got CORS blocked.

So there is no way to show the name of what is played?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.