Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 28, 2023 06:39 am GMT

How do you set up .env variables in your NextJS project ?

  1. First, ensure that the .env file is located in the root directory of your Next.js project.

  2. 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
  1. 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

Image description

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To