I have an MP3 file that I want to play when a button is clicked. However, I suspect that I am not correctly serving the file to the server. The following code snippet is from my project on Replit.com:
const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = process.env['port'];
const admin = require('firebase-admin');
const express = require("express");
const path = require("path");
admin.initializeApp();
const db = admin.firestore();
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index/index.html');
});
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index/script.js');
});
app.get('/', (req, res) => {
res.sendFile(__dirname + './index/ding.mp3');
});
io.on('connection', (socket) => {
socket.on('chat message', (msg) => {
if (msg === "ping") {
io.emit('chat message', "pong");
}
io.emit('chat message', msg);
});
socket.on('serverLog', (m) => {
console.log(m);
});
socket.on('loggedInWithName', (name) => {
console.log('User Connected. Username: ' + name);
});
});
http.listen(port, () => {
console.log(`Socket.IO server running at http://localhost:${port}`);
});
Check out this link on Replit.com for more details.