Jordan.B
Jordan.B

Reputation: 55

Error downloading file from my Node.js server

I'm trying to make a download link on my server for a zip file and I'm currently getting this error: (Note, still just testing it on local machine)

{ [Error: ENOENT: no such file or directory, stat 'C:\Users\Jordan\Desktop\Websites\HappyCamel\Users\Jordan\Desktop\Websites\HappyCamel']
errno: -4058,
code: 'ENOENT',
syscall: 'stat',
path: 'C:\\Users\\Jordan\\Desktop\\Websites\\HappyCamel\\Users\\Jordan\\Desktop\\Websites\\HappyCamel',
expose: false,
statusCode: 404,
status: 404 }

The relevant code is this:

router.get('/file/:name', function(req, res, next) {
    console.log('test123'); //successfully prints to console
    res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {
        console.log('test456'); //successfully prints to console
        if(err) { 
            console.log(err) //I'm assuming this is source of logged error
        } else {
            console.log("no error"); //doesn't print
        }
    });
})

edit:

Fixed it with changing this line:

res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {

to

res.download('./test123.zip', 'test123.zip', function(err) {

but now I get

angular.min.js:114 ReferenceError: success is not defined

error on my browser, but no errors in my node console (my "no error" line is printing)

Upvotes: 2

Views: 1806

Answers (1)

Nir Levy
Nir Levy

Reputation: 12953

you are using relative path. when you do this:

res.download('Users/Jordan/Desktop/Websites/HappyCamel/', 'test123.zip', function(err) {

it will look for Users/Jordan/Desktop/Websites/HappyCamel/ inside your current file's directory. looks like what you need is full path, or better a correct relative path- from the error it looks like the file is located with your code, so this should do:

res.download('./', 'test123.zip', function(err) {

Upvotes: 2

Related Questions