A
A
Andre19972022-01-25 10:57:38
Node.js
Andre1997, 2022-01-25 10:57:38

How to connect process.env to a node application so that variables can be set through the console?

I read about process.env, but I didn’t quite understand how it works
. I have an installed application with npm and I run it through the console npx playwright test
. Can I somehow specify the value for the variables in the console in this launch?
It seems that I stumbled upon process.env, but I could not quite understand if it can be used anywhere and how to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WapSter, 2022-01-25
@wapster92

MY_VAR="Hello world" node my-script.js

// my-script.js
console.log(process.env.MY_VAR) //Hello world

MY_VAR="Hello world" npx playwright test
Not sure, but in theory it should work. And it's easiest to store everything in .env files

R
Rag'n' Code Man, 2022-01-25
@iDmitriyWinX

process.argv or use dotenv

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question