I ask because Node.js on ubuntu does not seem to have the fs.exists () function. Although I can call it when I run Node.js on my Mac, when I deploy the server, it fails with the message that the function does not exist.
Now I know that some people consider an “anti-template” to check if a file exists, and then try and edit / open it, etc., but in my case I never delete these files, but I still need to check if they exist before they are written.
So how can I check if a directory (or file) exists?
EDIT:
This is the code that I run in a file called "temp.'s":
var fs=require('fs'); fs.exists('./temp.js',function(exists){ if(exists){ console.log('yes'); }else{ console.log("no"); } });
On my Mac, this works fine. On ubuntu, I get an error:
node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ TypeError: Object
On my Mac version: v0.13.0-pre On Ubuntu version: v0.6.12
source share