Sorry folks, but I am stuck.
This is the code:
let divisor = parseInt(env.get("DIVISOR")) || 2
let counter = context.get("counter") || 0
counter = (counter + 1) % divisor
context.set("counter", counter)
if (counter === 0) {
return msg
}
return null
But I am stumped on how to set the env part.
Obviously I'm missing something.
This is what chatGPT gave me, but I am still not seeing the env being defined/declared.
[{"id":"f1c2d3e4a5b6c7d8","type":"function","z":"9b7e7466.a4b698","name":"Rate limiter (1 in N)","func":"let divisor = parseInt(env.get(\"DIVISOR\")) || 2;\n\nlet counter = context.get(\"counter\") || 0;\ncounter = (counter + 1) % divisor;\ncontext.set(\"counter\", counter);\n\nif (counter === 0) {\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":4340,"y":3040,"wires":[[]]}]
Env(ironment) variables are not set in the function node. The image you've shared is for installing npm packages (libraries) for use inside the function node.
You might want to try looking in the config for your group. It has a button that looks like a bulleted list. In there you can set an environment variable. You can also set them in sub-flows and in flow tabs. Alternatively, you can set one at the OS level before starting Node-RED.
It does not make sense to me that you are using an environment variable for the divisor and a context variable for the counter, maybe it's more appropriate to use context variables for both.
If you really want to use an environment variable, there is no way to set it for a single function.
You can enclose the function within a group and set the variable for the group, but that would be easy to break if you happened to ungroup the group, not expecting it to change the program execution.
Completely agree. An env variable only makes sense if it is fairly static and you want to share it within a group or tab or sub-flow. For function nodes, you have the raw context variable which is already tied to that node.
Best way to think about env "variables" is to treat them as constants and not variable at all. They are only potentially variable outside the context of Node-RED.
The environment within which Node-red runs (on a Pi) includes a bunch of variables including, for example $USER, $PWD and $PATH.
These may be available within Node-red, but if so their value is constant, set at startup.
And then we have "environment variables" set within Node-red at flow, group or subflow level.
These are indeed variables and are an invention of the devil, shun them! 
Context variables should be available at these levels instead.
They are still mostly static, pre-defined in their own contexts. But yes, I agree, there probably should have been new context variable contexts for group, flow tab and sub-flow.
But there isn't so we take what we are given hey?!
Yeah, ok, the reasoning for me wanting to use an env is that I can change it as a variable.
Of course now - in retrospect - I would just define it at the top of the code.
Mia Culpa folks.
I just got hung up on something silly and applied it the wrong way.
Digression:
Originally I wanted to half the rate of messages getting through.
Bt then got the thought that maybe it could be less.
How do I make it that I just change ONE thing?
And somehow env snuck into my head and wouldn't get out.
Giving this code:
const divisor = 2
let counter = context.get("counter") || 0
counter = (counter + 1) % divisor
context.set("counter", counter)
if (counter === 0) {
return msg
}
return null
Yes?

Not forgetting that you can also rate-limit message flows:
Though that assumes you can think of a sensible message rate.