Configuring values in Next.js next.config.js involves exporting a JavaScript object with specific configuration options. Here’s a basic example of how you can configure values:
- Create a file named
next.config.jsin the root directory of your Next.js project if it doesn’t already exist. - Inside
next.config.js, export an object with the configuration options you want to set.
Here’s an example:
module.exports = {
// Your configuration options here
// For example:
env: {
API_URL: ‘https://example.com/api’,
SOME_OTHER_VARIABLE: ‘some_value’
},
// You can add more configuration options as needed
};
In this example, we’re using the env option to define environment variables that will be exposed to your Next.js application. These values can then be accessed anywhere in your code using process.env.
For instance, you can access the API_URL variable in your Next.js pages or components like this:
console.log(process.env.API_URL); // Output: https://example.com/api
Remember to restart your Next.js development server after making changes to next.config.js for the changes to take effect.