Node.js – how to set environment variables in code

You can not only consume environment variables in node with process.env but also set them. This will set the variable within your current node process and any child processes it calls, but not the calling shell itself.

// consume
var alreadySetEnvVarForDevice = process.env.NOBLE_HCI_DEVICE_ID

// set
process.env['NOBLE_HCI_DEVICE_ID'] = 1

Leave a Comment