0

I'm having issues getting dotenv to use the .env.development.local or .env.development file when starting in development mode. It only ever uses .env.

My package.json:

{
    "name": "server",
    "version": "1.0.0",
    "description": "",
    "scripts": {
        "build": "webpack",
        "start": "nodemon src/index.js"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "@babel/core": "^7.21.0",
        "@babel/preset-env": "^7.20.2",
        "babel-loader": "^9.1.2",
        "copy-webpack-plugin": "^11.0.0",
        "nodemon": "^2.0.20",
        "webpack": "^5.75.0",
        "webpack-cli": "^5.0.1",
        "webpack-node-externals": "^3.0.0"
    },
    "dependencies": {
        "cors": "^2.8.5",
        "dotenv": "^16.0.3",
        "express": "^4.18.2",
        "mongoose": "^6.9.0"
    }
}

Understanding of the heirarchy is as so:

.env.development.local > .env.local > .env.development > .env

With a few additional I have omitted which I don't plan to use.

I have been told that the issue is I need to specify the NODE_ENV somewhere in the start script but I have yet to find any documentation or guide showing me how to do that.

Jason Ayer
  • 621
  • 1
  • 10
  • 20
  • Does this answer your question? [What is NODE\_ENV and how to use it in Express?](https://stackoverflow.com/questions/16978256/what-is-node-env-and-how-to-use-it-in-express) – Ouroborus Mar 06 '23 at 22:00
  • @Ouroborus it actually does but how do I do the part that mentions that one should persist the setting of the variable so that it doesn't lose it on next PC shutdown/restart. It doesn't go into that. It offers a temporary solution via setting it in command line. Would it be referring to a Windows environment variable? My dev PC is windows. – Jason Ayer Mar 06 '23 at 22:17
  • At this point, you'd go back to Google and search something like "windows set env variable" – Ouroborus Mar 06 '23 at 22:23
  • I know how to set the windows environment variable, my question was is THAT what I need to do to make it persist? – Jason Ayer Mar 06 '23 at 22:26
  • Yes, that's how you set environment variables in Windows so that they persist through a reboot. If you set them by command or script, they usually last as long as that session lasts. The general case is that, when something talks about "environment variables", this is what they're talking about. They're typically exposed in the language in some way (such as `process.env` in Node) but they originally come from the system or shell. – Ouroborus Mar 06 '23 at 22:41

0 Answers0