fileService.doesFileExist( "assets", "audio/clips", possibleFileName, (err, result, response) => { // If no error occurred and the file exists, emit // the audio command. if (!err && result && result.exists) { const payload = { audioFile: possibleFileName }; // Send a message to the Socket.io socket.emit("onSoundEffect", payload); } } );