I would not use scripts to manage your variables, otherwise anytime you need to change them, you need to be changing the scripts. And in case you use Version Control to manage changes to your pipelines, it would require commits, etc. Why don't you leverage the release variables and set scopes for your variables (so variables for master, variables for staging env, variables for all environments, etc.). And the best part is, you can manage these variables from the Azure DevOps UI. Please have a look to this article.
Edit
Since you do not want to store these variables in your environment files together with the source of your node app, then you can manage those variables on the pipeline by defining them on the variables section, and then you can send those variables as arguments to your npm script - see more here.