nodejs fs.exists()


Question

I'm trying to call fs.exists in a node script but I get the error:

TypeError: Object # has no method 'exists'

I've tried replacing fs.exists() with require('fs').exists and even require('path').exists (just in case), but neither of these even list the method exists() with my IDE. fs is declared at the top of my script as fs = require('fs'); and I've used it previously to read files.

How can I call exists()?

1
18
11/27/2012 4:57:02 PM

Your require statement may be incorrect, make sure you have the following

var fs = require("fs");

fs.exists("/path/to/file",function(exists){
  // handle result
});

Read the documentation here

http://nodejs.org/api/fs.html#fs_fs_exists_path_callback

21
11/27/2012 4:59:19 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon