How to fix NodeJS Error: EXDEV: cross-device link not permitted, rename ...

Problem:

While trying to rename a file using fs.move() in NodeJS, you see an error message such as

Solution

This error occurs because you are moving a file from one drive (/tmp in our example above) to another drive (the current directory in our example above). On most platforms, this can’t be done using a simple rename operation.

Instead, fs.copyFile() the file.

For example, instead of

first, copy the file:

and then - if desired - remove the source file to mirror the behaviour of os.move() as closely as possible.

 


Check out similar posts by category: NodeJS