Closed aizazhussain341 closed 4 years ago
heres server.js
const express = require('express');
const cors = require('cors');
const ytdl = require('ytdl-core');
const app = express();
//app.use(cors());
app.listen(8000, () => { console.log('Server Works !!! At port 8000'); });
app.get('/downloadmp3', (req,res) => { var url = req.query.url; res.header('Content-Disposition', 'attachment; filename="audio.mp3"'); ytdl(url, { format: 'mp3', filter: 'audioonly' }).pipe(res); });
app.get('/downloadmp4', (req,res) => { var url = req.query.url; res.header('Content-Disposition', 'attachment; filename="video.mp4"'); ytdl(url, { format: 'mp4' }).pipe(res); }); `
Does the server run correctly when you use node index.js
?
thanks for replying but the issue was resolved it was internet issue. when internet got stable the issue was resolved <3
Sorry for the very late reply
No worries. Thanks
here is my script.js `var mp3Btn = document.getElementById('mp3'); var mp4Btn = document.getElementById('mp4'); var URLinput = document.querySelector('.URL-input'); var server = 'http://localhost:8000';
mp3Btn.addEventListener('click', () => { console.log(
URL: ${URLinput.value}
);redirectMp3(URLinput.value); });
mp4Btn.addEventListener('click', () => { console.log(
URL: ${URLinput.value}
);redirectMp4(URLinput.value); });
function redirectMp3(query) { window.location.href =
${server}/downloadmp3?url=${query}
; }function redirectMp4(query) { window.location.href =
${server}/downloadmp4?url=${query}
; }`