How to copy file in node.js (including modified time)?

copy, fs, node.js

Solution

There are methods in the `fs` module to access mtime:

var stat = fs.statSync(fromFilePath);
fs.utimesSync(toFilePath, stat.atime, stat.mtime)

Problem

I am able to copy a file in node.js using the following: ``` var readStream = fs.createReadStream(fromFilePath); readStream.pipe(fs.createWriteStream(toFilePath)); ``` The question is how to also copy/keep the modified time (mtime) like in a regular file copy command.

Original source