here is my index.js file
const express = require('express');
const cors = require('cors');
const ytdl = require('ytdl-core');
const app = express();
app.use(cors());
app.listen(4000, () => {
console.log('Server Works !!! At port 4000');
});
app.use(express.static(__dirname));
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);
});
I need someone to help me plz.If you find this you are an kind, observant person. Unless you are an A**hole. Then you’re just observant.
your browser is listening for a response at ‘/’ but there was no get request made at that route. does it work when you try ‘/downloadmp3’ or ‘/downloadmp4’ ?
Here is a quick Glitch project (Anonymous projects expire after 5 days)
Combining automated deployment, instant hosting & collaborative editing, Glitch gets you straight to coding so you can build full-stack web apps, fast
index.html
https://thunder-fierce-kitty.glitch.me
public/index.html
https://thunder-fierce-kitty.glitch.me/public
route ‘/express’ > JSON { message: “Hello from express”}
https://thunder-fierce-kitty.glitch.me/express
Yes.
index.html
<!DOCTYPE html>
<html>
<head>
<style>
* {
text-align: center;
}
.heading {
font-family: Arial;
margin-top:40vh;
}
.URL-input, .convert-button {
font-size:1.3em;
padding:5px 10px;
}
.URL-input {
border-radius:4px 0px 0px 4px;
width:30em;
text-align: left;
border:2px solid #EEEEEE;
background: #EEEEEE;
outline:none;
}
.URL-input:focus {
border:2px solid #0485ff;
}
.convert-button {
border-radius:0px 4px 4px 0px;
border:2px solid #0485ff;
background: #0485ff;
color:white;
}
</style>
<title>Games4U Video Downloader</title>
<script src='./script.js'></script>
</head>
<body>
<h1 class="heading">Games4U Video Downloader</h1>
<input class="URL-input" placeholder="Video URL e.g. https://www.youtube.com/watch?v=MtN1YnoL46Q">
<button class="convert-button">Convert</button>
</body>
</html>
So the files are inside the same root folder and the server is started from inside that folder?
Again, what about the other routes, do they work?
What happens if you make a folder named public (or whatever) and create an index.html inside it and point to that for the static serving?
app.use(express.static('public'))
It would help if you can upload your code to GitHub so we can see the full code and folder/file structure and package.json.
I’m new to coding and I took this here because there was problems with it. How would I do this?
Are you asking how to upload the code to GitHub?
https://help.github.com/en/github
No. Sorry if I caused confusion, but I meant how do I use different routes. I’ll get on uploading it to Github.
Did you fix it? Your code on GitHub works just fine for me.
Not really sure what you are asking here? You already added routes so you must know how to do it. What routes other then what you have do you need?