Bash environment variable not inherited by node process

Inlining the env works SOMETHING=hello node -e "console.log(process.env.SOMETHING)", but I want node to read the environment variables from the spawning shell.

The following code will print hello (note that echo can read the environment)

SOMETHING=hello
echo $SOMETHING

However the following code prints undefined:

SOMETHING=hello
node -e "console.log(process.env.SOMETHING)"

Why can’t node read the shell environment? Can I make it read that somehow?

Answer

Run like this:

export SOMETHING=hello
node -e "console.log(process.env.SOMETHING)"

OR

SOMETHING=test node -e "console.log(process.env.SOMETHING)"