I'm writing a command line interface based on Node.js, one part of which is to download an image from a given URL using this code, taken from this SO question:
var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
if (err) console.trace(err);
// Only do things if there is an image
if (parseInt(res.headers['content-length']) > 0) {
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
}
});
}
and save it locally. The file is then opened later on by this same Node.js application.
The issue is that when the Node.js package is installed like so:
npm install -g myNodeExecutable
It can run, but it doesn't have permission to save the image in the same folder, i.e. /usr/local/lib/node_modules/myNodeExecutable/img.jpg. Is there a directory that my Node.js executable will have access to? Let me know if you need details.