I am trying to pass a command line (specifically not in version control) option to my main index.js script, which does some stuff based on a specific S3 bucket.
In my package.json:
"scripts": {
"start": "bucket_name=${bucket_name:=null} node babel.runtime.js"
},
And via command line:
npm start -- --bucket_name="test"
But bucket_name keeps coming back as null, so the var isn't being passed correctly. I assume this is something simple, but I can't figure out what I'm doing wrong.
You presented two separate ways of assigning variables to the process.
The first one, using an npm script
"scripts": {
"start": "bucket_name=${bucket_name:=null} node babel.runtime.js"
}
This approach sets the bucket_name environment variable which is accessible from process.env.bucket_name.
The second approach, via command line
npm start -- --bucket_name="test"
This approach sets the bucket_name as an argument of the running process. This is accessible from process.argv array.
Its not that the variable isn't being set for one way or the other, its just about where you're accessing. Each of these sets the bucket_name in different places.
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