An Interest In:
Web News this Week
- April 28, 2024
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
April 28, 2023 06:39 am GMT
Original Link: https://dev.to/kamalthedev/how-do-you-set-up-env-variables-in-your-nextjs-project--fb5
How do you set up .env variables in your NextJS project ?
First, ensure that the .env file is located in the root directory of your Next.js project.
Make sure you have installed the required dependencies. You can use the dotenv package to load environment variables from the .env file. Run the following command to install it:
npm install dotenv
- Create a file named next.config.js in the root directory of your project if it doesn't exist already. In that file, add the following code
require('dotenv').config();module.exports = { env: { INFURA_IPFS_ID: process.env.INFURA_IPFS_ID, },};
This configuration will load the INFURA_IPFS_ID environment variable from the .env file and make it accessible in your Next.js app.
congratulations now you are good to go
After following these steps, you should be able to access the INFURA_IPFS_ID variable using process.env.INFURA_IPFS_ID in your code, just like you are doing with the projectId variable.
Original Link: https://dev.to/kamalthedev/how-do-you-set-up-env-variables-in-your-nextjs-project--fb5
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To