'How to run a Node JS script and pull ENV variables from server such as vercel?

I have a Node JS script that runs during my "prepare" stage during the build step on deployment to vercel. The script requires dotenv file like this:

const env = require("dotenv").config();

My issue is that requiring the dotenv file pulls from the local env file which is using my development CMS. I want the script to pull from the env file on vercel and no where else. How can I do this? Thank you for any advice.

My scripts in package.json

    "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "pre-commit": "yarn lint --fix && git add -A .",
    "format": "prettier --write",
    "prepare": "husky install && node ./pages/api/exampleScript",
},


Sources

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

Source: Stack Overflow

Solution Source