Tell us what’s happening:
Describe your issue in detail here.
Hi, this code worked on repl, but using it locally, something seems not to be work, is my .env file supposed to have a name? if so, what name? when requiring dotenv().config(), should it be saved to a variable? and am I supposed to app.use it? Your code so far
When using replit you only need use the SECRETS tab for your environment variables and don’t need a .env file at all.
If you’re working locally however, you’ll need a .env file (named as such) and also install the dotenv package, which you then require as (usually in server.js):
require('dotenv').config()
dotenv is used to load variables from the .env file into process.env, so that they can be used in your application.
but it says here " At the top of your myApp.js file, import and load the variables with require('dotenv').config() " , are you saying that in saving the .env file, nothing to should be behind the “.”?
Yes, the .env file is named simply .env.
You require dotenv at the top of your main app code, wherever that is.
As you get onto projects which are more involved, your code will become more modular, so your primary code will likely be in server.js, with routing code, logic and other stuff in separate files, imported as modules into server.js.