CodexBloom - Programming Q&A Platform

scenarios when deploying Node.js app to Oracle Cloud - how to to access environment variables

πŸ‘€ Views: 34 πŸ’¬ Answers: 1 πŸ“… Created: 2025-05-31
oracle-cloud node.js environment-variables JavaScript

I'm trying to deploy a Node.js application to Oracle Cloud using the Oracle Cloud Infrastructure (OCI) and I keep running into an scenario where my environment variables are not being recognized. My application relies on several environment variables for configuration, specifically `DB_URL` and `API_KEY`. I've set these environment variables in the OCI console under my application's settings, but when I try to access them in my Node.js application, they return as `undefined`. Here's a snippet of my code where I read the environment variables: ```javascript const express = require('express'); const app = express(); const dbUrl = process.env.DB_URL; const apiKey = process.env.API_KEY; app.get('/', (req, res) => { res.send(`DB_URL: ${dbUrl}, API_KEY: ${apiKey}`); }); app.listen(3000, () => { console.log('Server is running on port 3000'); }); ``` I have verified that the variables are indeed set in the OCI console, but when I run the application, I see the following output: ``` DB_URL: undefined, API_KEY: undefined ``` I’ve also tried running the app locally with a `.env` file using the `dotenv` package and it works perfectly. Here’s how I load the variables locally: ```javascript require('dotenv').config(); ``` But that doesn't seem to work in the Oracle Cloud environment. I’ve tried redeploying the application multiple times and checking the permissions, but nothing seems to resolve this scenario. Are there any special considerations for handling environment variables in OCI that I'm missing? Any help would be greatly appreciated!