Gabriel Llamas
Gabriel Llamas

Reputation: 18427

Command line interpreter for Windows using node.js

I'm currently porting some batch files to node.js. I feel more comfortable writing in JavaScript but for simple operations like copying a file, instead of:

copy in.txt out.txt

we have to write some more words...:

var fs = require ("fs");
var file = fs.createReadStream ("in.txt");
var newFile = fs.createWriteStream ("out.txt");

newFile.once ("open", function (fd){
    require ("util").pump (file, newFile);
});

If we want to remove a directory and all its content we have to use a recursive function, so 2 simple lines in batch are equivalent to a lot of lines in node.js.

I think that node.js it's so flexible and powerful and you know that windows cmd sucks, so I'm asking here if someone knows a good unix-style command line interpreter for node.js.

Thanks.

EDIT: I've done a FileUtils library for node.js -> https://github.com/Gagle/Node-FileUtils

Upvotes: 2

Views: 2907

Answers (3)

Joe White
Joe White

Reputation: 97696

You could try the fileutils package. It's short on documentation, but a quick skim through its source reveals copyFileToFile and copyFileIntoDir functions, and an rm method that recursively removes directories.

Upvotes: 1

user123444555621
user123444555621

Reputation: 152986

Thy ShellJS: https://github.com/arturadib/shelljs

Upvotes: 4

David Frantz
David Frantz

Reputation: 17

You are using the wrong tools. You would be far better off with BASH or Python. Personally I use Python on systems at work as itis almost ideal for such efforts.

Upvotes: 1

Related Questions