Is there a way to stream an mp3 file in a Node.js REPL on Replit?

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.

Answer №1

I have reviewed the repl and confirmed that it is functioning properly. Please review your volume settings.

Suggestion: To avoid having to repeat res.sendFile for every static file, I suggest using the following syntax:

app.use('/static', express.static(path.join(__dirname, 'public')))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular, Expressjs and Lusca form a powerful combination for protecting against cross-site

Currently, I am exploring csrf protection for my AngularJS and ExpressJS (4.x) application. I have been struggling to make the standard csrf package (https://www.npmjs.org/package/csrf) work and decided to give Lusca a try (https://www.npmjs.org/package/l ...

Capturing HTML form values and storing them in my JavaScript data object

I have a JS object with preset data as shown below in the variable var json. I am trying to create a simple HTML web form where I want the user inputs to be added as a new data set within my initial JS object. Here is the initial JS object data. The submi ...

Please ensure there is space reserved for the header above the content

Currently, I am working on creating a webpage with a unique banner design. My goal is for the content to scroll from the bottom and remain fixed directly under the upper portion of the banner. Initially, my idea was to have the content box take up the siz ...

How to use JavaScript and regex to control the state of a disabled submit button

I have a challenge where I need to activate or deactivate a submission button in a form called btn-vote using JavaScript. The button will only be activated if one of the 10 radio buttons is selected. Additionally, if the person-10 radio button is chosen, t ...

Position does not exist

I'm currently working on developing an application form that can be submitted by applicants based on the position they are interested in. However, I am facing an issue when trying to click submit on the application form, resulting in the error display ...

The issue arises with proptypes validation while implementing material-ui components

Just embarked on a new ReactJS project and ran into a plethora of errors when I integrated material-ui. One of the errors looked like this: bundle.js:12441 Warning: Failed Context Types: Calling PropTypes validators directly is not supported by the prop ...

Ways to set a header value before the initial body byte in express.js using hooks or callbacks

Within the global application-level middleware of express.js (4.16.4) and node.js (10.15.1), there is a specific requirement to set a cookie in the response header just before any middleware writes the initial byte to the body. An ideal solution would inv ...

Transform array sequences into their own unique sequences

Reorder Array of List to Fit My Custom Order Current Output: [ { "key": "DG Power Output", "value": "6.00", "unit": "kWh", }, { "key": "DG Run Time", "value": "5999999952", "unit": "minutes", }, { "key": "Fuel Level (Before)", "value": "8.00" ...

Creating a new music application and looking for ways to keep track of and update the number of plays for

I'm currently developing a music app and am looking for a way to update the play count every time a user listens to a song for at least 30 seconds. I've attempted the following approach: let current_final; let current_initial; ...

Clicking on a button in the Shield UI Grid Toolbar will apply filters to

Currently, I am working with a grid that utilizes a template for the toolbar. In this grid, there is a column labeled "Status." My goal is to filter the rows so that only those where the Status equals Request to Reschedule, Cancelled, Office Call Required, ...

The code encountered a parsing error at 11:1, due to the presence of

I'm having trouble with this code. I've searched for answers but haven't found any solutions. Here is the error message: 11:1 error Parsing error: Unexpected token } ✖ 1 problem (1 error, 0 warnings) npm ERR! code ELIFECYCLE npm ERR! ...

When using asynchronous code with an if/else statement, it is important to handle

My expertise in async code is limited, and I've hit a roadblock with a particular issue. Here's the snippet of code that's causing me trouble: if (!req.params.user_name) { req.params.user = req.me; } else { User.findOne({username: r ...

Manipulating variables in the main controller scope from a function in a transcluded directive scope using AngularJS

How can parent controller scope variables be updated from a transcluded directive scope's function? I have a situation where I am including directives within another directive using transclusion. Here is an example of how it is set up: <my-table& ...

Include HTML tag and class inside a JavaScript code block

A dynamic button is loaded when a certain condition in the JavaScript is met. Upon loading, I want to trigger a function (ClickMe) by clicking the button. However, I'm facing difficulty connecting the function with the button in my code. In my scrip ...

AngularJS causing a modal popup to appear even when the associated button is disabled

When using a Bootstrap modal popup form that opens on button click in AngularJS, I noticed that the modal still appears even when the button is disabled. Can someone help me understand why this happens? Here is the code for the button: <a class="btn b ...

The property length is undefined and cannot be read

I'm currently utilizing a dexi.io robot for the purpose of automating data extraction from permit databases. This particular robot has the capability to process custom JavaScript in order to dissect the incoming JSON object. While this code does func ...

What strategies can be implemented to enhance the create and update performance for a high volume of entries in Mongoose/MongoDB?

I am seeking the most efficient method to bulk create/update in my Express application that utilizes Mongoose/MongoDB. Is there a way to achieve this with a single database operation? On the frontend, users upload a CSV file which is then converted into a ...

Incorporate the block-input feature from sanity.io into your next.js blog for enhanced functionality

Currently, I'm in the process of creating a blog using next.js with sanity.io platform. However, I am facing some difficulties when it comes to utilizing the code-input plugin. What's working: I have successfully implemented the code component b ...

What is the best way to reorganize the switch case in order to invoke methods from a class?

I have a special character called Hero within my game, this Hero inherits characteristics from the Player class and can perform a variety of actions. The majority of these actions are customized to suit the Hero's abilities. class Hero extends Player ...

What impact does adding 'ng' in unit tests have on how promises are handled?

Here is an example of a service that utilizes $q.when to wrap a promise from a third-party library: // myService.js angular.module('myApp', []) .service('myService', function($q, $window) { var api = new $window.MyAPI(); this ...