'how to set env in Sheel for node.js [closed]

shell:$ set CONF = 44

const mytext = process.env.CONF console.log(mytext);

//undefined

enter image description here



Solution 1:[1]

In Powershell,

$Env:CONF = 'Hello, World!'

Solution 2:[2]

npm install dotenv --save

In your project root add .env file. Make sure you have the following in your .env file

CONF=SOME_DATA

In your js file add this

require('dotenv').config()
console.log(process.env.CONF) // remove this after you've confirmed it working

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rohit Gupta
Solution 2 Cris