Node.js DeploymentLesson 78Free preview
Node Env Variables
This lesson is part of Node.js · All levels
Summary
This lesson describes environment variables as a way to configure Node.js applications from outside the code. You read values through process.env, such as PORT, DATABASE_URL, and API_KEY. His best practice is to keep secrets in the uncommitted, then load them with the dotenv library.
Key points
- Process.env contains the Node process environment variable; its value is always a string.
- Install dotenv and call require('dotenv').config() to read the .env file.
- Add .env to .gitignore so that the secret does not enter the repository.
- Provide the default value: process.env.PORT not 3000 so that the application remains running locally.
- Common cases: NODE_ENV, DATABASE_URL, JWT_SECRET, API keys.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.