command-line-argumentsdenocmdline-args

How to pass command line arguments to Deno?


I have a Deno app, that I wish to pass some command line args to. I searched the manual, but found nothing.

I tried to use the same commands used in Node.js, assuming they might be sharing some for the std libraries, but it didn't work as well.

var args = process.argv.slice(2); 
// Uncaught ReferenceError: process is not defined

Any suggestions?


Solution

  • You can use Deno.args to access the command line arguments in Deno.

    To try it create a file test.ts :

    console.log(Deno.args);
    

    And run it with deno run test.ts firstArgument secondArgument

    It will return you with an array of the passed args:

    $ deno run test.ts firstArgument secondArgument
    [ "firstArgument", "secondArgument" ]