Samuel Rossille Samuel Rossille - 1 year ago 292
Node.js Question

Is node.js rmdir recursive ? Will it work on non empty directories?

The documentation for fs.rmdir is very short and doesn't explain the behavior of rmdir when the directory is not empty.

Q: What happens if I try to use this API to delete a non empty directory ?

Answer Source

Short answer: node.js fs.rmdir() calls the POSIX rmdir(); this will remove an empty directory, or return an error. In the given case, the call will invoke the callback function and pass the error as an exception.

The problem here is that the node.js documentation refers to POSIX:

The Node.js API Docs File System intro says:

File I/O is provided by simple wrappers around standard POSIX functions.

This almost changes the question into a duplicate of: Is there a listing of the POSIX API / functions?

The description for fs.rmdir is terse, but sufficient.

Asynchronous rmdir(2).

The rmdir(2) here is an implicit reference to the documentation for the rmdir() system call. The number (2) here is an old unix man page convention to indicate Section 2 of the Manual pages, containing the kernel interfaces.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download