Copying file in node.js build script -


im playing around javascript project, uses node build script.

it syncing folders built folder via

try {   fs.statsync('built/imgs'); } catch(err) {   if (err.code=='enoent') fs.symlinksync('../imgs', 'built/imgs');   else throw err; } 

whats corresponding fs command real copy of files built folder?

there no function in fs object copy whole directory. there's not 1 copy whole file.

however, quick , easy way copy 1 file.

var fs = require('fs');  fs.createreadstream('input_filename').pipe(fs.createwritestream('output_filename')); 

now need directory list. use fs.readdir or fs.readdirsync that.

so copy directory might this:

var dir = fs.readdirsync('.'); (var i=0; < dir.length; i++) {     fs.createreadstream(dir[i]).pipe(fs.createwritestream("newpath/"+dir[i])); } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -