Search code examples
node.jsbatch-file

Node.js Drag and Drop Support Windows


I'm using node.js as a scripting language locally on my machine.

Is it possible to implement drag and drop support in node.js using either .bat's or another technique that implements drag and drop support.


Solution

  • Simple save the following as a .bat. Then you can drag and drop files onto the script. Simple paste the data after the first four lines.

    @echo off
    "C:\Program Files\nodejs\node.exe" -p "eval(String(require(\"fs\").readFileSync(process.argv[1])).split(\"\n\").splice(3).join(\"\n\"));''" %0 %*
    exit
    
    var exec = require('child_process').exec, child;
    
    child = exec("C:\\Users\\a\\Desktop\\nb.nb",function (error, stdout, stderr) {
        if (error != null) {
          console.log('exec error: ' + error);
        }
    });
    
    /*
    var fs = require('fs');
    fs.stat(process.argv[2], function (err, stats) {
        console.log(stats.size);
      });
    */