# Package.json multi-env script setup

**URL:** <https://community.doppler.com/t/package-json-multi-env-script-setup/550>\
**Category:** Need Help\
**Created:** [March 8, 2022, 8:53pm UTC](https://community.doppler.com/t/package-json-multi-env-script-setup/550 "2022-03-08T20:53:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjuni](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@bjuni](https://community.doppler.com/u/bjuni)\
**Post date:** [March 8, 2022, 8:53pm UTC](https://community.doppler.com/t/package-json-multi-env-script-setup/550/1 "2022-03-08T20:53:01Z")

</div>

I want to have a package.json that looks something like:

```auto
"scripts": {
   "my-script": "doppler run -c ${ENV:-dev} -- node index.js",
}

```

index.js itself takes arguments, so I want to be calling this like `npm run my-script prod -- --my-arg-1 123 --my-arg-2 hello`

However, I’m getting errors because it’s passing “prod” in as an argument to the script itself, which is not what I want.

In case it’s helpful, I’m using [command-line-args - npm](https://www.npmjs.com/package/command-line-args) to parse the arguments within the script.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![watsonian](https://sea2.discourse-cdn.com/flex016/user_avatar/community.doppler.com/watsonian/32/267_2.png) [@watsonian](https://community.doppler.com/u/watsonian)\
**Post date:** [March 8, 2022, 9:22pm UTC](https://community.doppler.com/t/package-json-multi-env-script-setup/550/2 "2022-03-08T21:22:11Z")

</div>

Hi @bjuni!

Welcome to the Doppler Community!

Are you intending for the `prod` parameter to be used as the environment? If so, then you might try something like this:

```auto
"scripts": {
   "my-script": "doppler run -c ${npm_config_env:-dev} -- node index.js",
}

```

and then use a command like this:

```auto
npm run my-script --env=prod --my-arg-1=123 --my-arg-2=hello

```

Then, inside your script you can access those parameters with `process.env.npm_config_$NAME`. So, for `--my-arg-1` you would use `process.env.npm_config_my_arg_1`.

Will that work for what you’re after?

Regards,  
-Joel

---

<div class="post-metadata">

**Author:** ![bjuni](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@bjuni](https://community.doppler.com/u/bjuni)\
**Post date:** [March 8, 2022, 9:34pm UTC](https://community.doppler.com/t/package-json-multi-env-script-setup/550/3 "2022-03-08T21:34:17Z")

</div>

That’s one solution but it would get away from the intended usage of [command-line-args - npm](https://www.npmjs.com/package/command-line-args), so it’s not ideal
