0
votes

i want to download file that i upload to the server with node js and framework sailsjs

     $scope.download = function(l,n){
    console.log(n);
    var fs = require('fs');
    var http = require('http');
    var file = fs.createWriteStream(n);
    var request = http.get(l, function(response) {
        response.pipe(file);
    });
}

and when i click to download this error message i get: ReferenceError: require is not defined

in this 2 file : var fs = require('fs'); var http = require('http');

and i install before fs and http in npm install

thanks for the help

1
why do you want to download something you just uploaded? - dandavis
Does not have to be that only now I uploaded files, supposedly I have the ability to upload files to the server and I want an option also download all the files I upload - Ofir Kuberman

1 Answers

0
votes

require() method is a method to import other files into your code in node.js. node.js is server side javascript platform, which means it only runs on the server side. you're trying to write server side code on the client.

I can see you are using angular. if you're trying to make http requests to your server take a look at this: https://docs.angularjs.org/api/ng/service/$http