0

I am using node.js to launch an HTML file to display on the localhost:8000.
None of the media files that the HTML calls work. The HTML works fine when I launch it from the windows icon. I assume that I need to change how the media files are called.

I have tried moving the media files into the native folder.

//This is how I call the HTML.

var http = require('http'),
fs = require('fs');



fs.readFile('./index.html', function (err, html) {
    if (err) {
        throw err; 
    }       
    http.createServer(function(request, response) {  
        response.writeHeader(200, {"Content-Type": "text/html"});  
        response.write(html);  
        response.end();  
    }).listen(8000);
 });


 //This is how the media file is called in the HTML (index.html).

 <audio id="Whistle" src="C:\Site\Whistle.mp3" preload="auto" ></audio>

There is javascript in the HTML file that "plays" the file.

I am not getting any error messages from node.js or the web browser. It just isn't calling the file and moving on.

1 Answers1

0

I am not getting any error messages from node.js or the web browser

That's surprising because C:/... isn't a valid path. Rember that it is resolved on the client side, and there you don't have access to the servers file system. You also don't have access to the local file system the browser is running on for security reasons.

For sure you could send a request to the server instead, then the server could answer with a sound file.

Read on

Also make sure you know the basics

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
  • I am rookie at server side stuff. Can you recommend any options? –  Jun 19 '19 at 14:45
  • I think I understand what you're trying to do. E.g. Start a web server, then from your browser ask for the web page (e.g. http://localhost:8000). That webpage includes an mp3. I'd suggest looking up "Node Express basic examples". You don't need to use fs to read your html file. You can use Express to 'serve' your webpage. I don't mean to be deliberately vague, but you ought to read up a bit more. – Chris Adams Jun 19 '19 at 15:58