Vercel always return undefined for environment variables in Nodejs app

  Kiến thức lập trình

I have a simple nodejs application hosted on Vercel. From the code below only NODE_ENV returns a value. For both DATABASE_URL and SENDGRID_API_KEY I get back undefined. The env variables are added to the Environment Variable section in Vercel, and I have redeployed my application.

const express = require("express");
const cors = require("cors");
const app = express();
const port = process.env.PORT || 8000;

app.use(cors());
app.use(express.json());

app.get("/", (req, res) => {
  console.log('Hprocess.env.NODE_ENV', process.env.NODE_ENV);
  console.log('Hprocess.env.DATABASE_URL', process.env.DATABASE_URL);
  console.log('Hprocess.env.SENDGRID_API_KEY', process.env.SENDGRID_API_KEY);
  res.send("Hello");
});


app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
});

LEAVE A COMMENT