When working with NodeJS, I can pass the arguments to a Node script like this:
$ node node-server.js arg1 arg2=arg2-val arg3
And can get the arguments like so:
// print process.argv
process.argv.forEach(function (val, index, array) {
console.log(index + ': ' + val);
});
//Output
0: node
1: /Users/umar/work/node/node-server.js
2: arg1
3: arg2=arg2-val
4: arg3
How to get the command-line arguments in Deno?
Some experts suggested me to solve the problem by answers to the question
process.argv[0]
:Deno.execPath()
process.argv[1]
:Deno.mainModule
path.fromFileUrl
for conversions of URL to path string:import { fromFileUrl } from "https://deno.land/[email protected]/path/mod.ts";
const modPath = fromFileUrl(import.meta.url)
process.argv.slice(2)
:Deno.args
deno run --allow-read test.ts -foo -bar=baz 42
Deno.execPath(): <scoop path>\apps\deno\current\deno.exe
import.meta.url: file:///C:/path/to/project/test.ts
as path: C:\path\to\project\test.ts
Deno.args: [ "-foo", "-bar=baz", "42" ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With