Reputation: 251
env file
ID=123
I am able access this variable inside my pages/index.js file by
${process.env.ID}
but when I am trying same in my _app.js file its giving undefined, can anyone please suggest me how I can access this inside my _app.js file.
Upvotes: 2
Views: 1479
Reputation: 331
You can use process.env
but for security reasons the vars need to start with NEXT_PUBLIC_
(explained here).
In the .env
,
NEXT_PUBLIC_ID=123
In the _app.js
(or any front-end code),
process.env.NEXT_PUBLIC_ID
Upvotes: 3