How do I move files in node.js?

rizidoro picture rizidoro · Dec 20, 2011 · Viewed 193.2k times · Source

How can I move files (like mv command shell) on node.js? Is there any method for that or should I read a file, write to a new file and remove older file?

Answer

rizidoro picture rizidoro · Dec 20, 2011

According to seppo0010 comment, I used the rename function to do that.

http://nodejs.org/docs/latest/api/fs.html#fs_fs_rename_oldpath_newpath_callback

fs.rename(oldPath, newPath, callback)

Added in: v0.0.2

oldPath <String> | <Buffer>
newPath <String> | <Buffer>
callback <Function>

Asynchronous rename(2). No arguments other than a possible exception are given to the completion callback.