nextjs use environment variable


In a Next.js app, you can use environment variables to store sensitive information, such as API keys, that you don’t want to hardcode into your app. To use environment variables in your app, you can access them through the process.env object.

Here’s an example of how you can use an environment variable in a Next.js app:

import React from 'react'

function Example() {
    const apiKey = process.env.API_KEY

    return (
            The API key is {apiKey}.

In this example, we are using the API_KEY environment variable to access the API key. The process.env object contains all of the environment variables that are available to the app, and you can access a specific environment variable by its name (e.g., process.env.API_KEY).

It’s important to note that environment variables are only available on the server-side in a Next.js app. If you need to access environment variables in the browser, you can use the next/config module to expose them to the client-side.