title: How to play a sound from a socket.io event?
body: <p>I want to play a sound file on the client side whenever the space bar is pushed.</p>
  
  <p>The client side successfully emits the 'bang' event when the space bar is pressed: </p>
  
  <pre><code>$(window).keydown(function(event){
      alert(event.keyCode);
  if (event.keyCode == 32){
          socket.emit('bang'); 
  }
  });
  </code></pre>
  
  <p>The server side succesfully prints "bang" in the control.log so hopefully it is also emitting 'play':</p>
  
  <pre><code>io.on('connection', function(socket){
    socket.on('bang', function(){
      console.log('bang');
      io.emit('play');
    });
  });
  </code></pre>
  
  <p>However, back on the client side to play the sound, nothing is happening.
  The code I am using is:</p>
  
  <pre><code>var sound = new Audio('/public/audio/1.mp3');   
  
  socket.on('play', function () {
      sound.play();   
  });
  </code></pre>
  
  <p>Do I need to include something in the body to do with audio or a  in order to use the Audio object.</p>
  
  <p>I have searched this quite thoroughly but I am very new to node.js, html and socket.io.
  I tried the advice given here:
  <a href="https://stackoverflow.com/questions/24186848/play-audio-from-client-when-message-is-recieved-from-socket-io-node-js">Play Audio from client when message is recieved from socket.io - node.js</a></p>
  
  <p>But when I put in:</p>
  
  <pre><code>app.use('/public', express.static('/path/to/public'));
  </code></pre>
  
  <p>'static' became flagged and upon trying to run the code I recieved an error message: 'express is not defined, even though I put it before:</p>
  
  <pre><code>app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
  });
  </code></pre>
  
  <p>as advised in that post. I also tried it after and got the same error.</p>
  
  <p>Please help me.</p>