Node.js Processes & Environment Variables Explained

🚀Day 2/200-Exploring Node.js Processes & Environment Variables Today I worked on understanding how parent and child processes behave in Node.js. 🔹 What I learned: A child process is a completely separate process, not a thread fork() creates a new Node process and runs the file automatically By default, environment variables are inherited from parent → child We can also inject custom env variables into the child process 🔹 Experiment: I created a custom variable (MY_VAR) that: ❌ Does not exist in the parent ✅ Exists only in the child process 🔹 Key Insight: Environment variables are process-specific, not global 🔹 Challenges I faced: Tried accessing process.env in the terminal (wrong context ❌) Confused between terminal vs Node runtime Debugging child process separately from parent 🔹 Solution: Used console.log and debugger inside child.js Understood the difference between system env vs process env 💡 This helped me clearly understand how Node.js handles processes internally. #NodeJS #BackendDevelopment #JavaScript #LearningInPublic #Debugging #WebDevelopment

  • text

To view or add a comment, sign in

Explore content categories