<script> const button = document.getElementById('descargar-libro'); button.addEventListener('click', () => { // Llamada AJAX al servidor para obtener el enlace de descarga fetch('/descargar-libro', { method: 'POST', headers: { 'Content-Type': 'application/json' } }) .then(response => response.json()) .then(data => { // Redireccionar al enlace de descarga window.location.href = data.enlaceDescarga; }) .catch(error => console.error(error)); }); </script> Back-end (Node.js y Express):
Front-end (HTML, CSS y JavaScript):
app.get('/descargar-libro/:path', (req, res) => { const libroPath = req.params.path; res.download(libroPath, 'coquito.pdf'); }); Descargar libro coquito primer grado gratis pdf
Descarga de libro "Coquito" para primer grado <script> const button = document
const express = require('express'); const app = express(); const fs = require('fs'); const button = document.getElementById('descargar-libro')