Reputation: 25307
Im using node v0.6.12
This is my code:
var fs = require("fs");
fs.exists(".", function() {
console.log("Whatever);
});
I get this output:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object #<Object> has no method 'exists'
at Object.<anonymous> (/home/dbugger/Projects/nodetest/test.js:3:4)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:32)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:41)
Has "exists" been deprecated? What can I use then?
Upvotes: 5
Views: 5961
Reputation: 7820
I also had same problem in Raspberry Pi. Because if we just run
sudo apt-get install nodejs npm
this wont install latest version of NodeJs. In order to install newest version of NodeJs run this command
# Note the new setup script name for Node.js v0.10
curl -sL https://deb.nodesource.com/setup_0.10 | sudo bash -
# Then install with:
sudo apt-get install -y nodejs
Don't try to install Node.js v0.12 on Raspberry Pi. There is an unsolved issue is still there (https://raspberrypi.stackexchange.com/questions/24059/node-js-v0-11-14-exits-with-illegal-instruction)
If above method doesn't work, follow this one https://learn.adafruit.com/node-embedded-development/installing-node-dot-js
Upvotes: 0
Reputation: 38142
You can use path.exists()
but it's deprecated in the latest version of node. The preferred api is fs.exists()
these days, so you'll need to be prepared to switch at some point.
$ node --version
v0.8.3
$ node
> require('fs').exists
[Function]
> require('path').exists
[Function: deprecated]
The relevant docs:
Upvotes: 6
Reputation: 25307
Ok, upgrading to the latest version of node (0.8.12) solved the issue. Thanks :)
Upvotes: 1
Reputation: 12527
What is your node version? I get the same result on my machine (v0.6.14). I think the exists()
method has been moved from the path
module to the fs
module recently. Try path.exists()
Upvotes: 2