0

In my index.jade file I have

button(action="/download", type="button") Download Me! 

and within my index.js I have

var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); }); router.get('/download', function(req, res){ var file = __dirname + '/img/desktop-cover.jpg'; res.download(file); console.log(file); }); module.exports = router; 

I'm trying, on click of the button, to initiate the router.get('/download') that will download an image I have.

I may of misunderstood some of the documentation and i'm not sure why it isn't working.

Thanks!

8
  • 1
    "why it isn't working"— What is it doing? You're showing us the two extreme ends of the problem, but haven't described what actually happens, what the generated HTML looks like, if you get any errors or anything. Commented Sep 14, 2015 at 10:28
  • Sorry @Quentin I'm trying to download the file i'm passing through via res.download(file); so when I click on the button the action is /download that i've created a route for, and then the route will deliver a file Commented Sep 14, 2015 at 10:33
  • @GoodOldSnoopy but what is the error that's happening ? What happens when you try to download ? Commented Sep 14, 2015 at 10:35
  • Nothing, i've tried console logging it and get nothing back? Commented Sep 14, 2015 at 10:36
  • console.log(file); before res.download(file); Commented Sep 14, 2015 at 10:41

1 Answer 1

2

As button tag don't have any action attribute try to replace it with anchor tag.

try to replace button(action="/download", type="button") Download Me!

with

a(href='/download') Download Me!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.